-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.api.js
32 lines (27 loc) · 919 Bytes
/
node.api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import fs from 'fs';
import path from 'path';
export default pluginOptions => ({
afterExport: async state => {
const appDocsOutPrefix = 'dist/_in_app_help/';
const appDocsURLPrefix = 'docs/desktop/ui/';
for (const r of state.routes) {
// In-app docs
if (r.path.indexOf(appDocsURLPrefix) === 0) {
const id = r.path.replace(appDocsURLPrefix, '');
const _data = r.data?.docPage?.data;
if (!_data || !id || !_data?.excerpt) {
} else {
const data = {
title: _data.title,
excerpt: _data.excerpt,
link: _data.contents ? `/${r.path}` : undefined,
};
const dataJSON = JSON.stringify(data);
fs.mkdirSync(`${appDocsOutPrefix}${path.dirname(id)}`, { recursive: true });
fs.writeFileSync(`${appDocsOutPrefix}${id}.json`, dataJSON);
}
}
}
return state;
},
});