1 Star 0 Fork 649

吾惑/NocoBase

forked from NocoBase/NocoBase 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
.umirc.ts 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
chenos 提交于 2022-05-19 00:40 . feat: build, cli, devtools, sdk, docs...
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, lang = null) => {
const menuItems = [];
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: [
{
title: 'Docs',
path: '/',
hidden: true,
},
{
title: 'GitHub',
path: 'https://github.com/nocobase/nocobase',
},
],
menus: {
'/': parseMenuItems(menus, lang),
},
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/PoWERLimited/nocobase.git
[email protected]:PoWERLimited/nocobase.git
PoWERLimited
nocobase
NocoBase
main

搜索帮助