mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-13 17:05:47 +08:00
a5dd21e94a
* docs: refactor config * docs(build): support dev without pre build * docs: disable sourcemap
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { ensureLang } from '../utils/lang'
|
|
import guideLocale from '../i18n/pages/guide.json'
|
|
import componentLocale from '../i18n/pages/component.json'
|
|
|
|
function getGuideSidebar() {
|
|
return Object.fromEntries(
|
|
Object.entries(guideLocale).map(([lang, val]) => [
|
|
lang,
|
|
Object.values(val).map((item) => mapPrefix(item, lang)),
|
|
])
|
|
)
|
|
}
|
|
|
|
function getComponentsSideBar() {
|
|
return Object.fromEntries(
|
|
Object.entries(componentLocale).map(([lang, val]) => [
|
|
lang,
|
|
Object.values(val).map((item) => mapPrefix(item, lang, '/component')),
|
|
])
|
|
)
|
|
}
|
|
|
|
// return sidebar with language configs.
|
|
// this might create duplicated data but the overhead is ignorable
|
|
const getSidebars = () => {
|
|
return {
|
|
'/guide/': getGuideSidebar(),
|
|
'/component/': getComponentsSideBar(),
|
|
}
|
|
}
|
|
|
|
type Item = {
|
|
text: string
|
|
children?: Item[]
|
|
link?: string
|
|
}
|
|
|
|
function mapPrefix(item: Item, lang: string, prefix = '') {
|
|
if (item.children && item.children.length > 0) {
|
|
return {
|
|
...item,
|
|
children: item.children.map((child) => mapPrefix(child, lang, prefix)),
|
|
}
|
|
}
|
|
return {
|
|
...item,
|
|
link: `${ensureLang(lang)}${prefix}${item.link}`,
|
|
}
|
|
}
|
|
|
|
export const sidebars = getSidebars()
|