Skip to content

Commit e561e40

Browse files
authored
chore: update readme about server utils and Vite (#1052)
1 parent 3898bb1 commit e561e40

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,42 @@ interface NavigationLogo {
109109
}
110110
```
111111

112+
### Server utils
113+
114+
The package provides a set of server utilities for transforming your content.
115+
116+
```ts
117+
const {fullTransform} = require('@gravity-ui/page-constructor/server');
118+
119+
const {html} = fullTransform(content, {
120+
lang,
121+
extractTitle: true,
122+
allowHTML: true,
123+
path: __dirname,
124+
plugins,
125+
});
126+
```
127+
128+
Under the hood, a package is used to transform Yandex Flavored Markdown into HTML - `diplodoc/transfrom`, so it is also in peer dependencies
129+
130+
You can also use useful utilities in the places you need, for example in your custom components
131+
132+
```ts
133+
const {
134+
typografToText,
135+
typografToHTML,
136+
yfmTransformer,
137+
} = require('@gravity-ui/page-constructor/server');
138+
139+
const post = {
140+
title: typografToText(title, lang),
141+
content: typografToHTML(content, lang),
142+
description: yfmTransformer(lang, description, {plugins}),
143+
};
144+
```
145+
146+
You can find more utilities in this [section](https://github.com/gravity-ui/page-constructor/tree/main/src/text-transform)
147+
112148
### Custom blocks
113149

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

355+
#### Note about Vite
356+
357+
```ts
358+
import react from '@vitejs/plugin-react-swc';
359+
import dynamicImport from 'vite-plugin-dynamic-import';
360+
361+
export default defineConfig({
362+
plugins: [
363+
react(),
364+
dynamicImport({
365+
filter: (id) => id.includes('/node_modules/@gravity-ui/page-constructor'),
366+
}),
367+
],
368+
});
369+
```
370+
371+
For Vite, you need to install the `vite-plugin-dynamic-import` plugin and configure the config so that dynamic imports work
372+
319373
## Release flow
320374

321375
In usual cases we use two types of commits:

0 commit comments

Comments
 (0)