-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Generate sidebar and nav by version and language
玲珑文档需要保留多语言以及多版本的文档内容,对 sidebar 进行改造 Log: Generate sidebar
- Loading branch information
1 parent
36f2e76
commit 7508966
Showing
4 changed files
with
173 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Oops, something went wrong.