Skip to content

Commit

Permalink
chore: update readme about server utils and Vite (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaCG authored and qradle-yndx committed Nov 8, 2024
1 parent b1db9ab commit 5533835
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,42 @@ interface NavigationLogo {
}
```

### Server utils

The package provides a set of server utilities for transforming your content.

```ts
const {fullTransform} = require('@gravity-ui/page-constructor/server');

const {html} = fullTransform(content, {
lang,
extractTitle: true,
allowHTML: true,
path: __dirname,
plugins,
});
```

Under the hood, a package is used to transform Yandex Flavored Markdown into HTML - `diplodoc/transfrom`, so it is also in peer dependencies

You can also use useful utilities in the places you need, for example in your custom components

```ts
const {
typografToText,
typografToHTML,
yfmTransformer,
} = require('@gravity-ui/page-constructor/server');

const post = {
title: typografToText(title, lang),
content: typografToHTML(content, lang),
description: yfmTransformer(lang, description, {plugins}),
};
```

You can find more utilities in this [section](https://github.com/gravity-ui/page-constructor/tree/main/src/text-transform)

### Custom blocks

The page constructor lets you use blocks that are user-defined in their app. Blocks are regular React components.
Expand Down Expand Up @@ -316,6 +352,24 @@ npm ci
npm run dev
```

#### Note about Vite

```ts
import react from '@vitejs/plugin-react-swc';
import dynamicImport from 'vite-plugin-dynamic-import';

export default defineConfig({
plugins: [
react(),
dynamicImport({
filter: (id) => id.includes('/node_modules/@gravity-ui/page-constructor'),
}),
],
});
```

For Vite, you need to install the `vite-plugin-dynamic-import` plugin and configure the config so that dynamic imports work

## Release flow

In usual cases we use two types of commits:
Expand Down

0 comments on commit 5533835

Please sign in to comment.