Skip to content

Commit

Permalink
chore: Update the sidebar structure and document version
Browse files Browse the repository at this point in the history
- 更新 sidebar 的目录结构,引入版本字段,尽量减少重复部分,保留标题和文件路径部分,确保后续不同版本的,=标题和文件路径的可修改。
- sidebar 引入外部 json 文件,将需要频繁改动的标题、版本、文件路径部分统一编辑。
- 将文档版本统一使用两位版本号,前两位版本相同,功能兼容。

Log: update sidebar
  • Loading branch information
chenchongbiao authored and black-desk committed Dec 9, 2024
1 parent c11d42e commit 15ca6f1
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 112 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
run: |
# 定义版本和 commit 的映射关系
declare -A dict=(
["1.5.0"]="317ef66813e413adafeae5b01186b34eda514248"
["1.5.6"]="fd4ccd143d7e67b5c19cba3987043ae7db012ca8"
["1.5.x"]="fd4ccd143d7e67b5c19cba3987043ae7db012ca8"
# 添加更多的版本和 commit
)
# 遍历字典并检出每个 commit 到对应的目录
Expand Down
2 changes: 1 addition & 1 deletion .vitepress/theme/components/NewLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const lay = computed(() => {
const tips = computed(() => {
const { defaultVersion } = generateVersions()
let pathParts = route.path.split('/')
let versionPart = pathParts.find(part => /^\d+\.\d+\.\d+$/.test(part))
let versionPart = pathParts.find(part => /^\d+\.\d+\.x$/.test(part))
let _tips = ""

if (route.path.includes('/en/')) {
Expand Down
120 changes: 13 additions & 107 deletions .vitepress/theme/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,30 @@ const fs = require('fs');
const path = require('path');

const { generateVersions } = require('./versions.js')
const { versions } = generateVersions()
const { defaultVersion, versions } = generateVersions()

const langs = ['zh', 'en']

// 所有版本和语言的指南结构
let sidebar = {};

// 从外部 json 导入数据
const rawData = fs.readFileSync(path.resolve(__dirname, 'sidebar.json'));
// 定义每个类别及其子项的映射
const categoryMappings = {
"zh": {
"开始": {
"概述": "/start/whatis.md",
"安装": "/start/install.md",
"简单示例": "/start/how_to_use.md",
},
"ll-cli": {
"简介": "/ll-cli/introduction.md",
"列出已安装的应用": "/ll-cli/list.md",
"从远程仓库查询应用": "/ll-cli/query.md",
"安装应用": "/ll-cli/install.md",
"运行应用": "/ll-cli/run.md",
"卸载应用": "/ll-cli/uninstall.md",
"更新应用": "/ll-cli/update.md",
"查看运行中的应用": "/ll-cli/ps.md",
"进入容器内部": "/ll-cli/exec.md",
"强制退出应用": "/ll-cli/kill.md"
},
"ll-builder": {
"简介": "/ll-builder/introduction.md",
"创建项目": "/ll-builder/create.md",
"构建应用": "/ll-builder/build.md",
"运行应用": "/ll-builder/run.md",
"转换 appimage": "/ll-builder/convert.md",
"导出 layer 文件": "/ll-builder/export.md",
"配置文件": "/ll-builder/manifests.md",
"上架应用到商店": "/ll-builder/github.md"
},
"ll-pica": {
"简介": "/ll-pica/introduction.md",
"初始化配置": "/ll-pica/init.md",
"转换应用": "/ll-pica/convert.md",
"添加依赖": "/ll-pica/adep.md",
"转换配置文件简介": "/ll-pica/manifests.md",
},
"ll-appimage-convert": {
"简介": "/ll-appimage-convert/introduction.md",
"转换应用": "/ll-appimage-convert/convert-appimage.md",
},
"ll-flatpak-convert": {
"简介": "/ll-flatpak-convert/introduction.md",
"转换应用": "/ll-flatpak-convert/convert-flatpak.md",
},
"调试应用": {
"IDE中调试应用": "/debug/debug.md",
"常见构建问题": "/debug/ll-builder-faq.md",
"常见运行问题": "/debug/faq.md",
"常见转换问题": "/debug/ll-pica-faq.md",
}
},
"en": {
"Getting Started": {
"summary": "/start/whatis.md",
"Install": "/start/install.md",
"Simple example": "/start/how_to_use.md",
},
"ll-cli": {
"Introduction": "/ll-cli/introduction.md",
"List Installed Apps": "/ll-cli/list.md",
"Query Apps From Remote": "/ll-cli/query.md",
"Install App": "/ll-cli/install.md",
"Run App": "/ll-cli/run.md",
"Uninstall App": "/ll-cli/uninstall.md",
"Update App": "/ll-cli/update.md",
"View Running Apps": "/ll-cli/ps.md",
"Attach To Container": "/ll-cli/exec.md",
"Force Quit App": "/ll-cli/kill.md",
},
"ll-builder": {
"Introduction": "/ll-builder/introduction.md",
"Create Project": "/ll-builder/create.md",
"Build App": "/ll-builder/build.md",
"Run Compiled App": "/ll-builder/run.md",
"Convert AppImage": "/ll-builder/convert.md",
"Export Layer File": "/ll-builder/export.md",
"Manifests": "/ll-builder/manifests.md",
"App To Store": "/ll-builder/github.md"
},
"ll-pica": {
"ll-pica Introduction": "/ll-pica/introduction.md",
"Initialization configuration": "/ll-pica/init.md",
"Conversion application": "/ll-pica/convert.md",
"Add dependency": "/ll-pica/adep.md",
"Manifests": "/ll-pica/manifests.md",
},
"ll-appimage-convert": {
"Introduction": "/ll-appimage-convert/introduction.md",
"Conversion application": "/ll-appimage-convert/convert-appimage.md",
},
"ll-flatpak-convert": {
"Introduction": "/ll-flatpak-convert/introduction.md",
"Conversion application": "/ll-flatpak-convert/convert-flatpak.md",
},
"Debug App": {
"Debug App In IDE": "/debug/debug.md",
"Build FAQ": "/debug/ll-builder-faq.md",
"Run FAQ": "/debug/faq.md",
"Convert FAQ": "/debug/ll-pica-faq.md",
}
}
};
const categoryMappings = JSON.parse(rawData);

// 函数来生成特定语言和版本的指南结构
function generateSideba(pathPrefix, language) {
function generateSidebar(pathPrefix, language, version) {
lst = [];

for (const category in categoryMappings[language]) {
// 如果传入的 version 为空字符串,显示默认版本
if (version == '') {
version = defaultVersion
}

for (const category in categoryMappings[language][version]) {
const items = [];
Object.entries(categoryMappings[language][category]).forEach(([itemName, link]) => {
Object.entries(categoryMappings[language][version][category]).forEach(([itemName, link]) => {
// 检测 md 文件是否存在。
const fullFilePath = path.join(path.dirname(path.dirname(__dirname)), `${pathPrefix}${link}`);
if (fs.existsSync(fullFilePath)) {
Expand Down Expand Up @@ -147,7 +53,7 @@ versions.forEach(version => {
? `/${versionPrefix}guide`
: `/${versionPrefix}${language}/guide`;

sidebar[pathPrefix] = generateSideba(pathPrefix, language);
sidebar[pathPrefix] = generateSidebar(pathPrefix, language, version);
});

});
Expand Down
190 changes: 190 additions & 0 deletions .vitepress/theme/sidebar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"zh": {
"1.6.x": {
"开始": {
"概述": "/start/whatis.md",
"安装": "/start/install.md",
"简单示例": "/start/how_to_use.md"
},
"ll-cli": {
"简介": "/ll-cli/introduction.md",
"列出已安装的应用": "/ll-cli/list.md",
"从远程仓库查询应用": "/ll-cli/query.md",
"安装应用": "/ll-cli/install.md",
"运行应用": "/ll-cli/run.md",
"卸载应用": "/ll-cli/uninstall.md",
"更新应用": "/ll-cli/update.md",
"查看运行中的应用": "/ll-cli/ps.md",
"进入容器内部": "/ll-cli/exec.md",
"强制退出应用": "/ll-cli/kill.md"
},
"ll-builder": {
"简介": "/ll-builder/introduction.md",
"创建项目": "/ll-builder/create.md",
"构建应用": "/ll-builder/build.md",
"运行应用": "/ll-builder/run.md",
"转换 appimage": "/ll-builder/convert.md",
"导出 layer 文件": "/ll-builder/export.md",
"配置文件": "/ll-builder/manifests.md",
"上架应用到商店": "/ll-builder/github.md"
},
"ll-pica": {
"简介": "/ll-pica/introduction.md",
"初始化配置": "/ll-pica/init.md",
"转换应用": "/ll-pica/convert.md",
"添加依赖": "/ll-pica/adep.md",
"转换配置文件简介": "/ll-pica/manifests.md"
},
"ll-appimage-convert": {
"简介": "/ll-appimage-convert/introduction.md",
"转换应用": "/ll-appimage-convert/convert-appimage.md"
},
"ll-flatpak-convert": {
"简介": "/ll-flatpak-convert/introduction.md",
"转换应用": "/ll-flatpak-convert/convert-flatpak.md"
},
"调试应用": {
"IDE中调试应用": "/debug/debug.md",
"常见构建问题": "/debug/ll-builder-faq.md",
"常见运行问题": "/debug/faq.md",
"常见转换问题": "/debug/ll-pica-faq.md"
}
},
"1.5.x": {
"开始": {
"概述": "/start/whatis.md",
"安装": "/start/install.md",
"简单示例": "/start/how_to_use.md"
},
"ll-cli": {
"简介": "/ll-cli/introduction.md",
"列出已安装的应用": "/ll-cli/list.md",
"从远程仓库查询应用": "/ll-cli/query.md",
"安装应用": "/ll-cli/install.md",
"运行应用": "/ll-cli/run.md",
"卸载应用": "/ll-cli/uninstall.md",
"更新应用": "/ll-cli/update.md",
"查看运行中的应用": "/ll-cli/ps.md",
"进入容器内部": "/ll-cli/exec.md",
"强制退出应用": "/ll-cli/kill.md"
},
"ll-builder": {
"简介": "/ll-builder/introduction.md",
"创建项目": "/ll-builder/create.md",
"构建应用": "/ll-builder/build.md",
"运行应用": "/ll-builder/run.md",
"转换 appimage": "/ll-builder/convert.md",
"导出 layer 文件": "/ll-builder/export.md",
"配置文件": "/ll-builder/manifests.md",
"上架应用到商店": "/ll-builder/github.md"
},
"ll-pica": {
"简介": "/ll-pica/introduction.md",
"初始化配置": "/ll-pica/init.md",
"转换应用": "/ll-pica/convert.md",
"添加依赖": "/ll-pica/adep.md",
"转换配置文件简介": "/ll-pica/manifests.md"
},
"调试应用": {
"IDE中调试应用": "/debug/debug.md",
"常见构建问题": "/debug/ll-builder-faq.md",
"常见运行问题": "/debug/faq.md",
"常见转换问题": "/debug/ll-pica-faq.md"
}
}
},
"en": {
"1.6.x": {
"Getting Started": {
"summary": "/start/whatis.md",
"Install": "/start/install.md",
"Simple example": "/start/how_to_use.md"
},
"ll-cli": {
"Introduction": "/ll-cli/introduction.md",
"List Installed Apps": "/ll-cli/list.md",
"Query Apps From Remote": "/ll-cli/query.md",
"Install App": "/ll-cli/install.md",
"Run App": "/ll-cli/run.md",
"Uninstall App": "/ll-cli/uninstall.md",
"Update App": "/ll-cli/update.md",
"View Running Apps": "/ll-cli/ps.md",
"Attach To Container": "/ll-cli/exec.md",
"Force Quit App": "/ll-cli/kill.md"
},
"ll-builder": {
"Introduction": "/ll-builder/introduction.md",
"Create Project": "/ll-builder/create.md",
"Build App": "/ll-builder/build.md",
"Run Compiled App": "/ll-builder/run.md",
"Convert AppImage": "/ll-builder/convert.md",
"Export Layer File": "/ll-builder/export.md",
"Manifests": "/ll-builder/manifests.md",
"App To Store": "/ll-builder/github.md"
},
"ll-pica": {
"ll-pica Introduction": "/ll-pica/introduction.md",
"Initialization configuration": "/ll-pica/init.md",
"Conversion application": "/ll-pica/convert.md",
"Add dependency": "/ll-pica/adep.md",
"Manifests": "/ll-pica/manifests.md"
},
"ll-appimage-convert": {
"Introduction": "/ll-appimage-convert/introduction.md",
"Conversion application": "/ll-appimage-convert/convert-appimage.md"
},
"ll-flatpak-convert": {
"Introduction": "/ll-flatpak-convert/introduction.md",
"Conversion application": "/ll-flatpak-convert/convert-flatpak.md"
},
"Debug App": {
"Debug App In IDE": "/debug/debug.md",
"Build FAQ": "/debug/ll-builder-faq.md",
"Run FAQ": "/debug/faq.md",
"Convert FAQ": "/debug/ll-pica-faq.md"
}
},
"1.5.x": {
"Getting Started": {
"summary": "/start/whatis.md",
"Install": "/start/install.md",
"Simple example": "/start/how_to_use.md"
},
"ll-cli": {
"Introduction": "/ll-cli/introduction.md",
"List Installed Apps": "/ll-cli/list.md",
"Query Apps From Remote": "/ll-cli/query.md",
"Install App": "/ll-cli/install.md",
"Run App": "/ll-cli/run.md",
"Uninstall App": "/ll-cli/uninstall.md",
"Update App": "/ll-cli/update.md",
"View Running Apps": "/ll-cli/ps.md",
"Attach To Container": "/ll-cli/exec.md",
"Force Quit App": "/ll-cli/kill.md"
},
"ll-builder": {
"Introduction": "/ll-builder/introduction.md",
"Create Project": "/ll-builder/create.md",
"Build App": "/ll-builder/build.md",
"Run Compiled App": "/ll-builder/run.md",
"Convert AppImage": "/ll-builder/convert.md",
"Export Layer File": "/ll-builder/export.md",
"Manifests": "/ll-builder/manifests.md",
"App To Store": "/ll-builder/github.md"
},
"ll-pica": {
"ll-pica Introduction": "/ll-pica/introduction.md",
"Initialization configuration": "/ll-pica/init.md",
"Conversion application": "/ll-pica/convert.md",
"Add dependency": "/ll-pica/adep.md",
"Manifests": "/ll-pica/manifests.md"
},
"Debug App": {
"Debug App In IDE": "/debug/debug.md",
"Build FAQ": "/debug/ll-builder-faq.md",
"Run FAQ": "/debug/faq.md",
"Convert FAQ": "/debug/ll-pica-faq.md"
}
}
}
}
4 changes: 2 additions & 2 deletions .vitepress/theme/versions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function generateVersions() {
const versions = ['', '1.5.0', '1.5.6']; // 保留空用来判断默认路由
const versions = ['', '1.5.x']; // 保留空用来判断默认路由
return {
defaultVersion: '1.6.3', // 默认显示版本号
defaultVersion: '1.6.x', // 默认显示版本号
versions: versions
};
}

0 comments on commit 15ca6f1

Please sign in to comment.