mirror of
https://github.com/motajs/template.git
synced 2026-11-14 23:54:31 +08:00
init: 2.B
This commit is contained in:
commit
6bf32174d8
610 files changed
+151444
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import chokidar from 'chokidar';
|
||||
import { DefaultTheme } from 'vitepress';
|
||||
|
||||
const apiDir = path.resolve('./docs/api');
|
||||
const sidebarConfigPath = path.resolve('./docs/.vitepress/apiSidebar.ts');
|
||||
|
||||
const weight: Record<string, number> = {
|
||||
主页: 10,
|
||||
函数: 5
|
||||
};
|
||||
|
||||
function generateSidebar(): void {
|
||||
const sidebar: DefaultTheme.SidebarItem[] = [
|
||||
{ text: '目录', link: '/api/' }
|
||||
];
|
||||
|
||||
// 遍历 api 目录,查找 package 目录
|
||||
const packages = fs
|
||||
.readdirSync(apiDir)
|
||||
.filter(pkg => fs.statSync(path.join(apiDir, pkg)).isDirectory());
|
||||
|
||||
packages.forEach(pkg => {
|
||||
const pkgPath = path.join(apiDir, pkg);
|
||||
const files = fs
|
||||
.readdirSync(pkgPath)
|
||||
.filter(file => file.endsWith('.md'));
|
||||
|
||||
const items: DefaultTheme.SidebarItem[] = files.map(file => {
|
||||
const filePath = `api/${pkg}/${file}`;
|
||||
const fileName = path.basename(file, '.md');
|
||||
|
||||
return {
|
||||
text:
|
||||
fileName === 'index'
|
||||
? '主页'
|
||||
: fileName === 'functions'
|
||||
? '函数'
|
||||
: fileName,
|
||||
link: `/${filePath.replace(/\\/g, '/')}` // 兼容 Windows 路径
|
||||
};
|
||||
});
|
||||
|
||||
items.sort((a, b) => {
|
||||
const titleA = a.text ?? '';
|
||||
const titleB = b.text ?? '';
|
||||
return (weight[titleB] ?? 0) - (weight[titleA] ?? 0);
|
||||
});
|
||||
|
||||
sidebar.push({
|
||||
text: pkg,
|
||||
collapsed: true,
|
||||
items
|
||||
});
|
||||
});
|
||||
|
||||
// 生成 sidebar.ts
|
||||
const sidebarContent = `import { DefaultTheme } from 'vitepress';
|
||||
|
||||
export default ${JSON.stringify(
|
||||
sidebar,
|
||||
null,
|
||||
4
|
||||
)} as DefaultTheme.SidebarItem[];`;
|
||||
fs.writeFileSync(sidebarConfigPath, sidebarContent);
|
||||
console.log('✅ Sidebar 配置已更新');
|
||||
}
|
||||
|
||||
// 初次运行
|
||||
generateSidebar();
|
||||
|
||||
// 监听文件变动
|
||||
chokidar
|
||||
.watch(apiDir, { ignoreInitial: true })
|
||||
.on('add', filePath => {
|
||||
console.log(`📄 文件新增: ${filePath}`);
|
||||
generateSidebar();
|
||||
})
|
||||
.on('unlink', filePath => {
|
||||
console.log(`❌ 文件删除: ${filePath}`);
|
||||
generateSidebar();
|
||||
})
|
||||
.on('addDir', dirPath => {
|
||||
console.log(`📁 目录新增: ${dirPath}`);
|
||||
generateSidebar();
|
||||
})
|
||||
.on('unlinkDir', dirPath => {
|
||||
console.log(`📁 目录删除: ${dirPath}`);
|
||||
generateSidebar();
|
||||
})
|
||||
.on('raw', (event, path, details) => {
|
||||
if (event === 'rename') {
|
||||
console.log(`🔄 文件或文件夹重命名: ${path}`);
|
||||
generateSidebar();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,168 @@
|
||||
import { defineConfig } from 'vitepress';
|
||||
import { MermaidMarkdown, MermaidPlugin } from 'vitepress-plugin-mermaid';
|
||||
import api from './apiSidebar';
|
||||
import { join } from 'path';
|
||||
|
||||
// https://vitepress.dev/reference/site-config
|
||||
export default defineConfig({
|
||||
title: 'HTML5 魔塔样板 V2.B',
|
||||
description: 'HTML5 魔塔样板 V2.B 帮助文档',
|
||||
base: '/_docs/',
|
||||
markdown: {
|
||||
math: true,
|
||||
config(md) {
|
||||
md.use(MermaidMarkdown);
|
||||
}
|
||||
},
|
||||
outDir: join(process.cwd(), 'public', '_docs'),
|
||||
themeConfig: {
|
||||
// https://vitepress.dev/reference/default-theme-config
|
||||
outline: [2, 3],
|
||||
nav: [
|
||||
{ text: '主页', link: '/' },
|
||||
{ text: '指南', link: '/guide/quick-start' },
|
||||
{ text: 'API', link: '/api/' },
|
||||
{ text: '错误代码', link: '/logger/' }
|
||||
],
|
||||
sidebar: {
|
||||
'/guide/': [
|
||||
{
|
||||
text: '深度指南',
|
||||
items: [
|
||||
{ text: '快速开始', link: '/guide/quick-start' },
|
||||
|
||||
{ text: '差异说明', link: '/guide/diff' },
|
||||
{ text: '系统说明', link: '/guide/system' },
|
||||
{ text: '代码编写', link: '/guide/coding' },
|
||||
{ text: '音频系统', link: '/guide/audio' },
|
||||
{
|
||||
text: 'UI 系统',
|
||||
collapsed: false,
|
||||
items: [
|
||||
{ text: '快速浏览', link: '/guide/ui/' },
|
||||
{ text: '编写 UI', link: '/guide/ui/ui' },
|
||||
{ text: 'UI 元素', link: '/guide/ui/elements' },
|
||||
{
|
||||
text: '组件使用指南',
|
||||
link: '/guide/ui/component'
|
||||
},
|
||||
{ text: '优化性能', link: '/guide/ui/perf' },
|
||||
{ text: 'UI 系统', link: '/guide/ui/system' },
|
||||
{ text: '常见问题', link: '/guide/ui/faq' },
|
||||
{ text: '未来规划', link: '/guide/ui/future' }
|
||||
]
|
||||
},
|
||||
{
|
||||
text: '常见需求指南',
|
||||
collapsed: false,
|
||||
items: [
|
||||
{
|
||||
text: '快速浏览',
|
||||
link: '/guide/implements/index'
|
||||
},
|
||||
{
|
||||
text: '怪物特殊属性',
|
||||
link: '/guide/implements/special'
|
||||
},
|
||||
{
|
||||
text: '修改状态栏',
|
||||
link: '/guide/implements/status-bar'
|
||||
},
|
||||
{
|
||||
text: '新增 UI',
|
||||
link: '/guide/implements/new-ui'
|
||||
},
|
||||
{
|
||||
text: '主动技能',
|
||||
link: '/guide/implements/skill'
|
||||
},
|
||||
{
|
||||
text: '新增按键',
|
||||
link: '/guide/implements/hotkey'
|
||||
},
|
||||
{
|
||||
text: '动画效果',
|
||||
link: '/guide/implements/animate'
|
||||
},
|
||||
{
|
||||
text: '选择框与确认框',
|
||||
link: '/guide/implements/choice'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
'/logger/': [
|
||||
{
|
||||
text: '错误代码一览',
|
||||
items: [
|
||||
{
|
||||
text: '错误代码',
|
||||
collapsed: false,
|
||||
items: [
|
||||
{ text: '1-50', link: '/logger/error/error1' }
|
||||
]
|
||||
},
|
||||
{
|
||||
text: '警告代码',
|
||||
collapsed: false,
|
||||
items: [
|
||||
{ text: '1-50', link: '/logger/warn/warn1' },
|
||||
{ text: '51-100', link: '/logger/warn/warn2' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
'/api/': [
|
||||
{
|
||||
text: 'API 列表',
|
||||
items: api
|
||||
}
|
||||
]
|
||||
},
|
||||
socialLinks: [
|
||||
{ icon: 'github', link: 'https://github.com/unanmed/HumanBreak' }
|
||||
],
|
||||
search: {
|
||||
provider: 'local',
|
||||
options: {
|
||||
locales: {
|
||||
zh: {
|
||||
translations: {
|
||||
button: {
|
||||
buttonText: '搜索文档',
|
||||
buttonAriaLabel: '搜索文档'
|
||||
},
|
||||
modal: {
|
||||
noResultsText: '无法找到相关结果',
|
||||
resetButtonTitle: '清除查询条件',
|
||||
footer: {
|
||||
selectText: '选择',
|
||||
navigateText: '切换'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
locales: {
|
||||
root: {
|
||||
lang: 'zh',
|
||||
label: '中文'
|
||||
}
|
||||
},
|
||||
vite: {
|
||||
// @ts-expect-error 类型错误
|
||||
plugins: [MermaidPlugin()],
|
||||
optimizeDeps: {
|
||||
include: ['mermaid']
|
||||
},
|
||||
ssr: {
|
||||
noExternal: ['mermaid']
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
.mermaid {
|
||||
max-width: 600px; /* 限制最大宽度 */
|
||||
max-height: 400px; /* 限制最大高度 */
|
||||
overflow: auto; /* 允许滚动以防止超出 */
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
Reference in new issue
Block a user