Open didoee opened 1 year ago
这个自己写个脚本就好了其实
顺序什么的,好像也不好弄
import * as fs from 'node:fs';
import { join } from 'node:path';
function getTitle(content: string): string | null {
let mdTitle = content.match(/(?<=title:\s).+/gm);
if (mdTitle === null) return 'mdTitle';
return mdTitle[1];
}
function getTag(content: string, index?: number): string | string[] | null {
let tags = content.match(/(?<=tags:\s\[).+?(?=\])/gm);
if (tags === null) return tags;
if (!index || index > tags.length) {
return tags;
}
return tags[0].split(',')[index];
}
export function scanMdToCreateSidebarGroup(
scope: string,
path: string,
pure = false,
suffix: null | string
) {
const result: any = [];
const temp: any = [];
let allFile = fs.readdirSync(path);
for (const name of allFile) {
let info = fs.statSync(join(path, name));
if (info.isDirectory()) {
result.push({
text: name,
items: scanMdToCreateSidebarGroup(join(scope, name)
.replace('\\', '/'), join(path, name), true, suffix),
});
} else if (info.isFile() && /\.md$/.test(name)) {
temp.push({
text: name.slice(0, -3),
link: suffix ? `/${scope}/${name.replace(/\.md/, suffix)}` : `/${scope}/${name}`,
});
}
}
return pure ? temp : result;
}
我写了个侧边栏生成插件vite-plugin-vitepress-auto-sidebar,欢迎使用~
很希望有这个功能!在这之前,我的做法是:
更新:现在可以使用这个插件vitepress-plugin-auto-sidebar 来解决自动的问题 支持:
I think this should be an official "plugin" as it's the most common sidebar use of any standard user. My org uses Vue for all of our projects, however, we opt for Docusaurus purely for the out-of-the-box featureset (official means less risk of breakage happening under our feet!)
You can also consider the following solutions:
https://github.com/jooy2/vitepress-sidebar
It supports a lot of customization, alignment, frontmatter, and multiple sidebars.
really needed
really needed
You can use it to help you vite-plugin-vitepress-auto-sidebar
@cruvie You can auto sidebar with vitepress-auto-configure-nav-sidebar.
+1
希望可以实现 Hugo 中 book 主题的效果。 在 .md 文档中写 frontmatter 控制侧边栏标题位置,顺序以及隐藏
比如: --- title: 快速入门 # 在侧边栏显示的标题 weight: 1000 # 在本目录层级的权重值, 侧边栏该层的页面顺序按该值大小排序 bookCollapseSection: false # 是否折叠子层级的侧边栏目录 ---
非常非常推荐用这个插件, 我发现比另一个插件好用的多!
Really recommand this plugin! it's the best! https://github.com/jooy2/vitepress-sidebar?tab=readme-ov-file
Is your feature request related to a problem? Please describe.
建议新增自动提取md标题作为sidebar
Describe the solution you'd like
建议新增自动提取md标题作为sidebar
Describe alternatives you've considered
No response
Additional context
No response
Validations