mirror of
https://github.com/Gar-b-age/CookLikeHOC.git
synced 2025-12-26 03:48:31 +08:00
fix: 定义变量,减少重复代码
This commit is contained in:
parent
ca6fa28d0f
commit
09ed73b159
@ -60,17 +60,17 @@ export function generateNavAndSidebar(rootDir: string) {
|
||||
|
||||
// Find README.md、readme.md、index.md
|
||||
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) {
|
||||
sidebar[`/${dir}/`] = [
|
||||
{
|
||||
text: dir,
|
||||
link: readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : undefined,
|
||||
items: items.filter((i) => i.link !== (readme ? `/${encodeURI(dir)}/${encodeURI(readme)}` : undefined)),
|
||||
link: readmeURI,
|
||||
items: items.filter((i) => i.link !== readmeURI),
|
||||
},
|
||||
]
|
||||
if (readme) {
|
||||
nav.push({ text: dir, link: `/${encodeURI(dir)}/${encodeURI(readme)}` })
|
||||
nav.push({ text: dir, link: readmeURI })
|
||||
} else {
|
||||
nav.push({ text: dir, link: items[0].link! })
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user