1 Star 4 Fork 2

聪小陈/inula

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
plugin.ts 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
聪小陈 提交于 2023-12-26 18:03 . fix: docs page error
import { IApi } from '@aluni/types';
import { winPath } from '@umijs/utils';
import { copyFileSync, existsSync, readFileSync, writeFileSync } from 'fs';
import { dirname, join } from 'path';
export default (api: IApi) => {
api.onStart(() => {
// 修复当配置 base 时, @umijs/plugin-docs 首页判断 bug
const layoutPath = winPath(
join(
dirname(require.resolve('@umijs/plugin-docs')),
'..',
'client/theme-doc/Layout.tsx',
),
);
// window.location.pathname === '/'
let context = readFileSync(layoutPath, 'utf-8');
context = context.replace(
"window.location.pathname === '/'",
`window.location.pathname === '${api.config.base ?? '/'}'`,
);
writeFileSync(layoutPath, context, 'utf-8');
});
api.onBuildComplete(({ err }) => {
//@ts-ignore
if (!err && !existsSync(join(api.paths.absOutputPath!, '404.html'))) {
// 如果没有 404 则复制一下 index
setTimeout(() => {
copyFileSync(
join(api.paths.absOutputPath!, 'index.html'),
join(api.paths.absOutputPath!, '404.html'),
);
}, 500);
}
});
api.onGenerateFiles((args) => {
api.writeTmpFile({
path: 'index.ts',
content: `export { FeatureIItem } from '${join(
api.cwd,
'docs',
'components',
'Item',
)}'`,
});
});
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/congxiaochen/inula.git
git@gitee.com:congxiaochen/inula.git
congxiaochen
inula
inula
master

搜索帮助