Skip to content

Commit

Permalink
feat: Generate sidebar and nav by version and language
Browse files Browse the repository at this point in the history
玲珑文档需要保留多语言以及多版本的文档内容,对 sidebar 进行改造

Log: Generate sidebar
chenchongbiao authored and black-desk committed May 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 36f2e76 commit 325dce6
Showing 5 changed files with 200 additions and 202 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -15,8 +15,38 @@ concurrency:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['1.4.3'] # 定义版本数组
steps:
- uses: actions/checkout@v3
- name: Checkout linglong ${{ matrix.version }}
uses: actions/checkout@v4
with:
ref: ${{ matrix.version }} # 使用矩阵中的版本号作为检出的ref
path: ${{ matrix.version }} # 每个版本检出到不同的目录
repository: linuxdeepin/linglong
sparse-checkout: |
docs/pages
sparse-checkout-cone-mode: false
- name: checkout 1.4.3 docs
uses: actions/checkout@v4
with:
ref: 2ba2407e1148b3a084f71269660272a9348360ab # homepage 项目的 v1.4.3
path: '1.4.3'
repository: linuxdeepin/linglong-homepage
sparse-checkout: |
en
guide
sparse-checkout-cone-mode: false
- name: Generate Versions JS File
run: |
verPath=".vitepress/theme/versions.js"
echo "const versions = [''];" > $verPath
for ver in "${{ matrix.version }}"; do
echo "versions.push('$ver');" >> $verPath
done
echo "exports.versions = versions;" >> $verPath
- uses: actions/setup-node@v3
with:
node-version: 16
213 changes: 11 additions & 202 deletions .vitepress/config.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

const { sidebar } = require('./theme/sidebar.js')
const { generateNav } = require('./theme/nav.js');

module.exports = {
head: [
[
@@ -29,217 +32,23 @@ module.exports = {
lang: "zh-CN",
title: "玲珑",
description: "独立包格式",
themeConfig: {
nav: generateNav('zh')
}
},
en: {
lang: "en-US",
title: "linglong",
description: "hermetic package format",
themeConfig: {
nav: generateNav('en')
}
},
},
themeConfig: {
logo: "/asset/logo.svg",
siteTitle: false,
sidebar: {
"/guide/": [
{
collapsible: true,
text: "开始",
items: [
// { text: "玲珑是什么", link: "/guide/start/whatis.md" },
{ text: "安装", link: "/guide/start/install.md" },
],
},
{
collapsible: true,
text: "命令行工具",
items: [
{ text: "简介", link: "/guide/ll-cli/introduction.md" },
{
text: "列出已安装的应用",
link: "/guide/ll-cli/list.md",
},
{
text: "从远程仓库查询应用",
link: "/guide/ll-cli/query.md",
},
{ text: "安装应用", link: "/guide/ll-cli/install.md" },
{ text: "运行应用", link: "/guide/ll-cli/run.md" },
{
text: "卸载应用",
link: "/guide/ll-cli/uninstall.md",
},
{ text: "更新应用", link: "/guide/ll-cli/update.md" },
{
text: "查看运行中的应用",
link: "/guide/ll-cli/ps.md",
},
{ text: "进入容器内部", link: "/guide/ll-cli/exec.md" },
{ text: "强制退出应用", link: "/guide/ll-cli/kill.md" },
],
// TODO:add cli doc to here
},
{
collapsible: true,
text: "构建工具",
items: [
{
text: "简介",
link: "/guide/ll-builder/introduction.md",
},
{
text: "创建项目",
link: "/guide/ll-builder/create.md",
},
{
text: "构建应用",
link: "/guide/ll-builder/build.md",
},
{ text: "运行应用", link: "/guide/ll-builder/run.md" },
{
text: "导出uab格式应用",
link: "/guide/ll-builder/export.md",
},
{
text: "配置文件",
link: "/guide/ll-builder/manifests.md",
},
// { text: "推送uab到远程仓库", link: "/guide/ll-builder/push.md" },
// { text: "本地demo示例", link: "/guide/ll-builder/demo.md" },
{
text: "上架应用到商店",
link: "/guide/ll-builder/github.md",
},
],
// TODO:add builder doc to here
},
{
collapsible: true,
text: "调试应用",
items: [
{
text: "IDE中调试应用",
link: "/guide/debug/debug.md",
},
{
text: "常见构建问题",
link: "/guide/debug/ll-builder-faq.md",
},
{ text: "常见运行问题", link: "/guide/debug/faq.md" },
],
// TODO:add builder doc to here
},
],
"/en/guide/": [
{
collapsible: true,
text: "Getting Start",
items: [
// { text: "玲珑是什么", link: "/guide/start/whatis.md" },
{
text: "Install Linglong Environment",
link: "/en/guide/start/install.md",
},
],
},
{
collapsible: true,
text: "Command Line Tools",
items: [
{
text: "Introduction",
link: "/en/guide/ll-cli/introduction.md",
},
{
text: "List Installed Apps",
link: "/en/guide/ll-cli/list.md",
},
{
text: "Query Apps From Remote",
link: "/en/guide/ll-cli/query.md",
},
{
text: "Install App",
link: "/en/guide/ll-cli/install.md",
},
{ text: "Run App", link: "/en/guide/ll-cli/run.md" },
{
text: "Uninstall App",
link: "/en/guide/ll-cli/uninstall.md",
},
{
text: "Update App",
link: "/en/guide/ll-cli/update.md",
},
{
text: "View Running Apps",
link: "/en/guide/ll-cli/ps.md",
},
{
text: "Attach To Container",
link: "/en/guide/ll-cli/exec.md",
},
{
text: "Force Quit App",
link: "/en/guide/ll-cli/kill.md",
},
],
// TODO:add cli doc to here
},
{
collapsible: true,
text: "Build Tools",
items: [
{
text: "Introduction",
link: "/en/guide/ll-builder/introduction.md",
},
{
text: "Create Project",
link: "/en/guide/ll-builder/create.md",
},
{
text: "Build App",
link: "/en/guide/ll-builder/build.md",
},
{
text: "Run Compiled App",
link: "/en/guide/ll-builder/run.md",
},
{
text: "Export Uab Format",
link: "/en/guide/ll-builder/export.md",
},
{
text: "Manifests",
link: "/en/guide/ll-builder/manifests.md",
},
// { text: "Push Uab To Remote Repository", link: "/en/guide/ll-builder/push.md" },
// { text: "Local demo", link: "/en/guide/ll-builder/demo.md" },
{
text: "App To Store",
link: "/en/guide/ll-builder/github.md",
},
],
// TODO:add builder doc to here
},
{
collapsible: true,
text: "Debug App",
items: [
{
text: "Debug App In IDE",
link: "/en/guide/debug/debug.md",
},
{
text: "Build FAQ",
link: "/en/guide/debug/ll-builder-faq.md",
},
{ text: "Run FAQ", link: "/en/guide/debug/faq.md" },
],
// TODO:add builder doc to here
},
],
},
sidebar: sidebar,
locales: {
"/": {
nav: [
@@ -327,7 +136,7 @@ module.exports = {
],
},
],
},
}
},
socialLinks: [
{ icon: "github", link: "https://github.com/linuxdeepin" },
42 changes: 42 additions & 0 deletions .vitepress/theme/nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { versions } = require('./versions.js')

// 定义每个类别及其子项的映射
const categoryMappings = {
"zh": {
"item": "版本",
"defaultVersion": "主分支",
"link": "/start/install.md"
},
"en": {
"item": "Version",
"defaultVersion": "master",
"link": "/start/install.md"
}
}

// 函数来生成特定语言和版本的导航栏
function generateNav(language) {
lst = [];
const items = [];
// 检测 md 文件是否存在。
versions.forEach(version => {
const versionPrefix = version ? `${version}/` : '';
const pathPrefix = language === 'zh'
? `/${versionPrefix}guide`
: `/${versionPrefix}${language}/guide`;
const defaultVersion = version ? `${version}` : categoryMappings[language]['defaultVersion'];
items.push({
text: defaultVersion,
link: `${pathPrefix}${categoryMappings[language]['link']}`
});
});

lst.push({
text: categoryMappings[language]['item'],
ariaLabel: "Version Menu",
items: items
});
return lst;
}

module.exports = { generateNav };
115 changes: 115 additions & 0 deletions .vitepress/theme/sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
const fs = require('fs');
const path = require('path');

const { versions } = require('./versions.js')
const langs = ['zh', 'en']

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

// 定义每个类别及其子项的映射
const categoryMappings = {
"zh": {
"开始": {
"安装": "/start/install.md",
},
"命令行工具": {
"简介": "/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/introduction.md",
"创建项目": "/ll-builder/create.md",
"构建应用": "/ll-builder/build.md",
"运行应用": "/ll-builder/run.md",
"导出uab格式应用": "/ll-builder/export.md",
"配置文件": "/ll-builder/manifests.md",
"上架应用到商店": "/ll-builder/github.md"
},
"调试应用": {
"IDE中调试应用": "/debug/debug.md",
"常见构建问题": "/debug/ll-builder-faq.md",
"常见运行问题": "/debug/faq.md"
}
},
"en": {
"Getting Started": {
"Install Linglong Environment": "/start/install.md",
},
"Command Line Tools": {
"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",
},
"Build Tools": {
"Introduction": "/ll-builder/introduction.md",
"Create Project": "/ll-builder/create.md",
"Build App": "/ll-builder/build.md",
"Run Compiled App": "/ll-builder/run.md",
"Export Uab Format": "/ll-builder/export.md",
"Manifests": "/ll-builder/manifests.md",
"App To Store": "/ll-builder/github.md"
},
"Debug App": {
"Debug App In IDE": "/debug/debug.md",
"Build FAQ": "/debug/ll-builder-faq.md",
"Run FAQ": "/debug/faq.md"
}
}
};

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

for (const category in categoryMappings[language]) {
const items = [];
Object.entries(categoryMappings[language][category]).forEach(([itemName, link]) => {
// 检测 md 文件是否存在。
const fullFilePath = path.join(path.dirname(path.dirname(__dirname)), `${pathPrefix}${link}`);
if (fs.existsSync(fullFilePath)) {
items.push({
text: itemName,
link: `${pathPrefix}${link}`
});
}
});

lst.push({
collapsible: true,
text: category,
items: items
});
}
return lst;
}


versions.forEach(version => {
langs.forEach(language => {
const versionPrefix = version ? `${version}/` : '';
const pathPrefix = language === 'zh'
? `/${versionPrefix}guide`
: `/${versionPrefix}${language}/guide`;

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

});

exports.sidebar = sidebar
2 changes: 2 additions & 0 deletions .vitepress/theme/versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const versions = [''];
exports.versions = versions;

0 comments on commit 325dce6

Please sign in to comment.