mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:25:52 +00:00
796e73ae5a
* refactor(doc): change to new structure * docs: add database docs * docs: add collection docs * docs: add db field examples * docs(api): fix filename and menu path * docs: add database docs * docs: add db operators doc * docs: add resourcer menu * docs: add resourcer docs * docs: fix api docs * docs: refactor api menu structure * feat: update docs (#830) * feat: updates * feat: update docs * chore: ignore docs from ci Co-authored-by: Junyi <mytharcher@users.noreply.github.com> Co-authored-by: mytharcher <mytharcher@gmail.com> * docs: add database methods docs * docs: add missed api * docs: fix api docs * feat: update development docs (#833) * feat: update development docs * feat: update docs * feat: update docs * docs: add first plugin example (#834) * feat: update docs * feat: update docs * docs: fix typo Co-authored-by: chenos <chenlinxh@gmail.com>
149 lines
3.2 KiB
TypeScript
149 lines
3.2 KiB
TypeScript
import transformer from '@umijs/preset-dumi/lib/transformer';
|
|
import { defineConfig } from 'dumi';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import menus from './docs/menus';
|
|
|
|
const lang = process.env.DOC_LANG || 'en-US';
|
|
|
|
console.log('process.env.DOC_LANG', process.env.DOC_LANG);
|
|
|
|
const findFilePath = (filename, lang) => {
|
|
const filePath = path.resolve(__dirname, `docs/${lang}/${filename}`);
|
|
if (fs.existsSync(`${filePath}.md`)) {
|
|
return `${filePath}.md`;
|
|
}
|
|
return;
|
|
};
|
|
|
|
const markdown = (filename, lang) => {
|
|
const filePath = findFilePath(filename, lang);
|
|
if (!filePath) {
|
|
return;
|
|
}
|
|
return transformer.markdown(fs.readFileSync(filePath, 'utf8').toString(), filePath);
|
|
};
|
|
|
|
const getPath = (value: string) => {
|
|
if (!value) {
|
|
return '';
|
|
}
|
|
const keys = value.split('/');
|
|
if (keys.pop() === 'index') {
|
|
return keys.join('/') || '/';
|
|
}
|
|
return value;
|
|
};
|
|
|
|
const getTitle = (item, lang) => {
|
|
if (lang) {
|
|
return item[`title.${lang}`] || item.title;
|
|
}
|
|
return item.title;
|
|
};
|
|
|
|
const parseMenuItems = (items: any[], lang: string) => {
|
|
const menuItems: any[] = [];
|
|
for (const item of items) {
|
|
if (typeof item === 'string') {
|
|
const result = markdown(item, lang);
|
|
if (result) {
|
|
menuItems.push({
|
|
title: result.meta.title,
|
|
disabled: result.meta.disabled,
|
|
path: getPath(item),
|
|
});
|
|
}
|
|
} else if (item.children) {
|
|
menuItems.push({
|
|
...item,
|
|
title: getTitle(item, lang),
|
|
children: parseMenuItems(item.children, lang),
|
|
});
|
|
} else if (item.path) {
|
|
menuItems.push({
|
|
...item,
|
|
title: getTitle(item, lang),
|
|
path: getPath(item.path),
|
|
});
|
|
} else {
|
|
menuItems.push({
|
|
title: getTitle(item, lang),
|
|
...item,
|
|
});
|
|
}
|
|
}
|
|
return menuItems;
|
|
};
|
|
|
|
export default defineConfig({
|
|
title: 'NocoBase',
|
|
outputPath: `./docs/dist/${lang}`,
|
|
mode: 'site',
|
|
resolve: {
|
|
includes: [`./docs/${lang}`],
|
|
},
|
|
locales: [[lang, lang]],
|
|
hash: true,
|
|
logo: 'https://www.nocobase.com/images/logo.png',
|
|
navs: {
|
|
'en-US': [
|
|
{
|
|
title: 'Introduction',
|
|
path: '/introduction'
|
|
},
|
|
{
|
|
title: 'Getting started',
|
|
path: '/getting-started'
|
|
},
|
|
{
|
|
title: 'Manual',
|
|
path: '/manual'
|
|
},
|
|
{
|
|
title: 'Development',
|
|
path: '/development'
|
|
},
|
|
{
|
|
title: 'API reference',
|
|
path: '/api'
|
|
},
|
|
{
|
|
title: 'GitHub',
|
|
path: 'https://github.com/nocobase/nocobase',
|
|
},
|
|
],
|
|
'zh-CN': [
|
|
{
|
|
title: '介绍',
|
|
path: '/introduction'
|
|
},
|
|
{
|
|
title: '快速开始',
|
|
path: '/getting-started'
|
|
},
|
|
{
|
|
title: '使用手册',
|
|
path: '/manual'
|
|
},
|
|
{
|
|
title: '开发教程',
|
|
path: '/development'
|
|
},
|
|
{
|
|
title: 'API 参考',
|
|
path: '/api'
|
|
},
|
|
{
|
|
title: 'GitHub',
|
|
path: 'https://github.com/nocobase/nocobase',
|
|
},
|
|
]
|
|
},
|
|
menus: Object.keys(menus).reduce((result, key) => {
|
|
const items = menus[key];
|
|
result[key] = parseMenuItems(items, lang);
|
|
return result;
|
|
}, {})
|
|
});
|