2022-05-19 00:40:55 +08:00
|
|
|
import transformer from '@umijs/preset-dumi/lib/transformer';
|
2021-04-17 21:33:21 +08:00
|
|
|
import { defineConfig } from 'dumi';
|
2022-05-19 00:40:55 +08:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2022-09-19 09:23:01 +08:00
|
|
|
const parseMenuItems = (items: any[], lang: string) => {
|
|
|
|
const menuItems: any[] = [];
|
2022-05-19 00:40:55 +08:00
|
|
|
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;
|
|
|
|
};
|
2021-12-03 07:31:22 +08:00
|
|
|
|
2021-04-17 21:33:21 +08:00
|
|
|
export default defineConfig({
|
2021-11-16 11:06:17 +08:00
|
|
|
title: 'NocoBase',
|
2022-05-19 00:40:55 +08:00
|
|
|
outputPath: `./docs/dist/${lang}`,
|
2021-10-28 22:55:51 +08:00
|
|
|
mode: 'site',
|
2022-01-10 19:22:21 +08:00
|
|
|
resolve: {
|
2022-05-19 00:40:55 +08:00
|
|
|
includes: [`./docs/${lang}`],
|
2022-01-10 19:22:21 +08:00
|
|
|
},
|
2022-05-19 00:40:55 +08:00
|
|
|
locales: [[lang, lang]],
|
2022-01-10 19:22:21 +08:00
|
|
|
hash: true,
|
2022-05-19 00:40:55 +08:00
|
|
|
logo: 'https://www.nocobase.com/images/logo.png',
|
2022-09-19 09:23:01 +08:00
|
|
|
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'
|
|
|
|
},
|
|
|
|
{
|
2022-09-30 12:41:23 +08:00
|
|
|
title: '插件开发',
|
2022-09-19 09:23:01 +08:00
|
|
|
path: '/development'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'API 参考',
|
|
|
|
path: '/api'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'GitHub',
|
|
|
|
path: 'https://github.com/nocobase/nocobase',
|
|
|
|
},
|
|
|
|
]
|
2022-05-19 00:40:55 +08:00
|
|
|
},
|
2022-09-19 09:23:01 +08:00
|
|
|
menus: Object.keys(menus).reduce((result, key) => {
|
|
|
|
const items = menus[key];
|
|
|
|
result[key] = parseMenuItems(items, lang);
|
|
|
|
return result;
|
|
|
|
}, {})
|
2021-04-17 21:33:21 +08:00
|
|
|
});
|