mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 18:01:24 +08:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
|
const guideLocale = require('./i18n/pages/guide.json')
|
||
|
const componentLocale = require('./i18n/pages/component.json')
|
||
|
const { ensureLang } = require('./site-utils')
|
||
|
|
||
|
function getGuideSidebar() {
|
||
|
const guideSidebars = {}
|
||
|
Object.entries(guideLocale).forEach(([lang, val]) => {
|
||
|
guideSidebars[lang] = Object.values(val).map((item) => {
|
||
|
return mapPrefix(item, lang)
|
||
|
})
|
||
|
})
|
||
|
return guideSidebars
|
||
|
}
|
||
|
|
||
|
function getComponentsSideBar() {
|
||
|
const componentSidebar = {}
|
||
|
Object.entries(componentLocale).forEach(([lang, val]) => {
|
||
|
componentSidebar[lang] = Object.values(val).map((item) => {
|
||
|
return mapPrefix(item, lang, '/component')
|
||
|
})
|
||
|
})
|
||
|
|
||
|
return componentSidebar
|
||
|
}
|
||
|
|
||
|
// return sidebar with language configs.
|
||
|
// this might create duplicated data but the overhead is ignorable
|
||
|
const getSidebars = () => {
|
||
|
return {
|
||
|
'/guide/': getGuideSidebar(),
|
||
|
'/component/': getComponentsSideBar(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function mapPrefix(item, lang, prefix = '') {
|
||
|
if (item.children && item.children.length > 0) {
|
||
|
return {
|
||
|
...item,
|
||
|
children: item.children.map((child) => {
|
||
|
return mapPrefix(child, lang, prefix)
|
||
|
}),
|
||
|
}
|
||
|
}
|
||
|
return {
|
||
|
...item,
|
||
|
link: `${ensureLang(lang)}${prefix}${item.link}`,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = getSidebars()
|