|
|
@ -86,7 +86,7 @@ function side(baseDir: string, options?: Options) { |
|
|
|
const filePath = path.resolve(baseDir, item) |
|
|
|
let p = filePath + ".md" |
|
|
|
const { |
|
|
|
data: { title, first, name }, |
|
|
|
data: { title, first, name, category }, |
|
|
|
} = grayMatter(fs.readFileSync(p, "utf8")); |
|
|
|
const [pkg, _name, i] = item.split('/').slice(-3) |
|
|
|
|
|
|
@ -97,6 +97,27 @@ function side(baseDir: string, options?: Options) { |
|
|
|
|
|
|
|
if (sidebarItemIndex !== -1) { |
|
|
|
if (first!=undefined) { |
|
|
|
if(category) { |
|
|
|
// @ts-ignore
|
|
|
|
let ff = sidebars.find(v=>v._category === category) |
|
|
|
if(!ff) { |
|
|
|
ff = { |
|
|
|
text: category, |
|
|
|
// @ts-ignore
|
|
|
|
_sort: 0, |
|
|
|
// @ts-ignore
|
|
|
|
_category: category, |
|
|
|
items: [] |
|
|
|
} |
|
|
|
// @ts-ignore
|
|
|
|
sidebars.push(ff) |
|
|
|
} |
|
|
|
// @ts-ignore
|
|
|
|
ff.items.push({ |
|
|
|
text: _title, |
|
|
|
link: '/' + item.replace('index', ''), |
|
|
|
}); |
|
|
|
} else { |
|
|
|
sidebars[sidebarItemIndex].items.splice(first,0,{ |
|
|
|
text: _title, |
|
|
|
link: '/' + item.replace('index', ''), |
|
|
@ -104,17 +125,61 @@ function side(baseDir: string, options?: Options) { |
|
|
|
if (name) { |
|
|
|
sidebars[sidebarItemIndex].text = name |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
if(category) { |
|
|
|
// @ts-ignore
|
|
|
|
let ff = sidebars.find(v=>v._category === category) |
|
|
|
if(!ff) { |
|
|
|
ff = { |
|
|
|
text: category, |
|
|
|
// @ts-ignore
|
|
|
|
_sort: 0, |
|
|
|
// @ts-ignore
|
|
|
|
_category: category, |
|
|
|
items: [] |
|
|
|
} |
|
|
|
// @ts-ignore
|
|
|
|
sidebars.push(ff) |
|
|
|
} |
|
|
|
// @ts-ignore
|
|
|
|
ff.items.push({ |
|
|
|
text: _title, |
|
|
|
link: '/' + item.replace('index', ''), |
|
|
|
}); |
|
|
|
} else { |
|
|
|
sidebars[sidebarItemIndex].items.push({ |
|
|
|
text: _title, |
|
|
|
link: '/' + item.replace('index', ''), |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
sidebars[sidebarItemIndex].items.sort((a,b)=>{ |
|
|
|
// @ts-ignore
|
|
|
|
return a._sort - b._sort |
|
|
|
}) |
|
|
|
} else { |
|
|
|
if(category) { |
|
|
|
// @ts-ignore
|
|
|
|
let ff = sidebars.find(v=>v._category === category) |
|
|
|
if(!ff) { |
|
|
|
ff = { |
|
|
|
text: category, |
|
|
|
// @ts-ignore
|
|
|
|
_sort: -999, |
|
|
|
// @ts-ignore
|
|
|
|
_category: category, |
|
|
|
items: [] |
|
|
|
} |
|
|
|
// @ts-ignore
|
|
|
|
sidebars.push(ff) |
|
|
|
} |
|
|
|
// @ts-ignore
|
|
|
|
ff.items.push({ |
|
|
|
text: _title, |
|
|
|
link: '/' + item.replace('index', ''), |
|
|
|
}); |
|
|
|
} else { |
|
|
|
sidebars.push({ |
|
|
|
text: name || curDir, |
|
|
|
// @ts-ignore
|
|
|
@ -128,11 +193,16 @@ function side(baseDir: string, options?: Options) { |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
sidebars.sort((a,b)=>{ |
|
|
|
// @ts-ignore
|
|
|
|
return (a._sort || 0) - (b._sort || 0) |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
sidebars.sort((a,b)=>{ |
|
|
|
// @ts-ignore
|
|
|
|
return a._sort - b._sort |
|
|
|
return b._sort - a._sort |
|
|
|
}) |
|
|
|
|
|
|
|
// const sidebars: Sidebar = [];
|
|
|
|