mirror of
https://github.com/Gar-b-age/CookLikeHOC.git
synced 2026-07-21 12:06:19 +00:00
fix: 定义变量,减少重复代码
This commit is contained in:
@@ -60,17 +60,17 @@ export function generateNavAndSidebar(rootDir: string) {
|
|||||||
|
|
||||||
// Find README.md、readme.md、index.md
|
// Find README.md、readme.md、index.md
|
||||||
const readme = ['README.md', 'readme.md', 'index.md'].find((n) => fs.existsSync(path.join(abs, n)))
|
const readme = ['README.md', 'readme.md', 'index.md'].find((n) => fs.existsSync(path.join(abs, n)))
|
||||||
|
const readmeURI = readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : "/";
|
||||||
if (items.length > 0) {
|
if (items.length > 0) {
|
||||||
sidebar[`/${dir}/`] = [
|
sidebar[`/${dir}/`] = [
|
||||||
{
|
{
|
||||||
text: dir,
|
text: dir,
|
||||||
link: readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : undefined,
|
link: readmeURI,
|
||||||
items: items.filter((i) => i.link !== (readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : undefined)),
|
items: items.filter((i) => i.link !== readmeURI),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
if (readme) {
|
if (readme) {
|
||||||
nav.push({ text: dir, link: `/${encodeURI(dir)}/${encodeURI(readme)}` })
|
nav.push({ text: dir, link: readmeURI })
|
||||||
} else {
|
} else {
|
||||||
nav.push({ text: dir, link: items[0].link! })
|
nav.push({ text: dir, link: items[0].link! })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user