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
  • Loading branch information
chenchongbiao committed Apr 30, 2024
1 parent 36f2e76 commit 7508966
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 202 deletions.
213 changes: 11 additions & 202 deletions .vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
[
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -327,7 +136,7 @@ module.exports = {
],
},
],
},
}
},
socialLinks: [
{ icon: "github", link: "https://github.com/linuxdeepin" },
Expand Down
44 changes: 44 additions & 0 deletions .vitepress/theme/nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { versions } = require('./versions.js')

let nav = {};

// 定义每个类别及其子项的映射
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 };
Loading

0 comments on commit 7508966

Please sign in to comment.