vitepress: generate sidebar by md files automatically

This commit is contained in:
Ruabbit
2024-12-06 13:14:44 +08:00
parent 3456957e9c
commit dfa38414df
6 changed files with 213 additions and 97 deletions
+193 -96
View File
@@ -1,96 +1,193 @@
import { defineConfig } from "vitepress"; import { defineConfig } from "vitepress";
import fs from "fs";
// https://vitepress.dev/reference/site-config import path from "path";
export default defineConfig({
title: "爱特工作室(CCF海大学生分会)WIKI", function getMarkdownFiles(dirPath: string): { text: string; link: string }[] {
description: "Wiki for ITStudio.", if (!fs.existsSync(dirPath)) return [];
head: [["link", { rel: "icon", href: "/favicon.ico" }]], return fs
lang: "zh-CN", .readdirSync(dirPath)
srcDir: "src", .filter(
themeConfig: { (file) =>
logo: "/logo.png", file.endsWith(".md") &&
siteTitle: "ITSTUDIO WIKI", !file.startsWith(".") &&
search: { !file.startsWith("_") &&
provider: "local", file !== "index.md"
}, )
nav: [ .sort()
{ text: "Home", link: "/" }, .map((file) => ({
{ text: "Wiki", link: "/wiki/about/intro" } text:
], file.replace(/\.md$/, "").charAt(0).toUpperCase() +
file.replace(/\.md$/, "").slice(1),
sidebar: { link:
"/wiki": [ "/" +
// { path
// text: "ITStudio Wiki", .relative(path.join(__dirname, "../src"), path.join(dirPath, file))
// link: "/wiki", .replace(/\.md$/, "")
// }, .replace(/\\/g, "/"),
{ }));
text: "团队介绍", }
// link: "/wiki/about",
items: [{ text: "爱特工作室简介", link: "/wiki/about/intro" }], // https://vitepress.dev/reference/site-config
}, export default defineConfig({
{ title: "爱特工作室(CCF海大学生分会)WIKI",
text: "新闻公告", description: "Wiki for ITStudio.",
// link: "/wiki/news", head: [
items: [ ["link", { rel: "icon", href: "/favicon.ico" }],
{ ["meta", { name: "theme-color", content: "#3eaf7c" }],
text: "近期新闻", ["meta", { name: "apple-mobile-web-app-capable", content: "yes" }],
link: "/wiki/news/recent-news", [
collapsed: false, "meta",
items: [], { name: "apple-mobile-web-app-status-bar-style", content: "black" },
}, ],
{ ],
text: "活动公告", lang: "zh-CN",
link: "/wiki/news/events", srcDir: "src",
collapsed: false, lastUpdated: true,
items: [],
}, themeConfig: {
], logo: "/logo.png",
}, siteTitle: "ITSTUDIO WIKI",
{
text: "技术与专业领域", // Enable search
// link: "/wiki/tech", search: {
items: [ provider: "local",
{ options: {
text: "技术博客", translations: {
link: "/wiki/tech/blog", button: {
collapsed: false, buttonText: "搜索文档",
items: [], buttonAriaLabel: "搜索文档",
}, },
{ modal: {
text: "成员项目", noResultsText: "无法找到相关结果",
link: "/wiki/tech/projects", resetButtonTitle: "清除查询条件",
collapsed: false, footer: {
items: [], selectText: "选择",
}, navigateText: "切换",
], closeText: "关闭",
}, },
{ },
text: "生活感悟", },
link: "/wiki/life", },
}, },
{
text: "联系方式与友情链接", // Navigation
items: [ nav: [
{ { text: "Home", link: "/" },
text: "联系方式", { text: "Wiki", link: "/wiki/about/intro" },
link: "/wiki/contact/contatusus", {
collapsed: false, text: "相关链接",
items: [], items: [
}, { text: "官方网站", link: "https://www.itstudio.club/" },
{ { text: "GitHub", link: "https://github.com/ITStudioOUC" },
text: "友情链接", ],
link: "/wiki/contact/link", },
collapsed: false, ],
items: [],
}, sidebar: {
], "/wiki": [
}, {
], text: "团队介绍",
}, items: [{ text: "爱特工作室简介", link: "/wiki/about/intro" }],
socialLinks: [ },
{ icon: "googlehome", link: "https://www.itstudio.club/" }, {
{ icon: "github", link: "https://github.com/ITStudioOUC" }, text: "新闻公告",
], items: [
}, {
}); text: "近期新闻",
link: "/wiki/news/recent-news",
collapsed: false,
items: getMarkdownFiles(
path.join(__dirname, "../src/wiki/news/recent-news")
),
},
{
text: "活动公告",
link: "/wiki/news/events",
collapsed: false,
items: getMarkdownFiles(
path.join(__dirname, "../src/wiki/news/events")
),
},
],
},
{
text: "技术与专业领域",
items: [
{
text: "技术博客",
link: "/wiki/tech/blog",
collapsed: false,
items: getMarkdownFiles(
path.join(__dirname, "../src/wiki/tech/blog")
),
},
{
text: "成员项目",
link: "/wiki/tech/projects",
collapsed: false,
items: getMarkdownFiles(
path.join(__dirname, "../src/wiki/tech/projects")
),
},
],
},
{
text: "生活感悟",
link: "/wiki/life",
items: getMarkdownFiles(path.join(__dirname, "../src/wiki/life")),
},
{
text: "联系方式与友情链接",
items: [
{
text: "联系方式",
link: "/wiki/contact/contatusus",
collapsed: false,
items: getMarkdownFiles(
path.join(__dirname, "../src/wiki/contact/contatusus")
),
},
{
text: "友情链接",
link: "/wiki/contact/link",
collapsed: false,
items: getMarkdownFiles(
path.join(__dirname, "../src/wiki/contact/link")
),
},
],
},
],
},
// Social links
socialLinks: [
{ icon: "github", link: "https://github.com/ITStudioOUC/ITStudio-Wiki" },
],
// Footer
footer: {
message: "Released under the Apache License 2.0",
copyright: "Copyright 2002-present ITStudio",
},
// Edit link
editLink: {
pattern:
"https://github.com/ITStudioOUC/ITStudio-Wiki/edit/main/src/:path",
text: "在 GitHub 上编辑此页",
},
// Doc footer
docFooter: {
prev: "上一页",
next: "下一页",
},
// Outline
outline: {
level: [2, 3],
label: "目录",
},
},
});
+18
View File
@@ -5,6 +5,7 @@
"packages": { "packages": {
"": { "": {
"devDependencies": { "devDependencies": {
"@types/node": "^18.0.0",
"vitepress": "^1.5.0" "vitepress": "^1.5.0"
} }
}, },
@@ -1136,6 +1137,16 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/node": {
"version": "18.19.67",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-18.19.67.tgz",
"integrity": "sha512-wI8uHusga+0ZugNp0Ol/3BqQfEcCCNfojtO6Oou9iVNGPTL6QNSdnUdqq85fRgIorLhLMuPIKpsN98QE9Nh+KQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~5.26.4"
}
},
"node_modules/@types/unist": { "node_modules/@types/unist": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmmirror.com/@types/unist/-/unist-3.0.3.tgz", "resolved": "https://registry.npmmirror.com/@types/unist/-/unist-3.0.3.tgz",
@@ -2204,6 +2215,13 @@
"url": "https://github.com/sponsors/wooorm" "url": "https://github.com/sponsors/wooorm"
} }
}, },
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
"dev": true,
"license": "MIT"
},
"node_modules/unist-util-is": { "node_modules/unist-util-is": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmmirror.com/unist-util-is/-/unist-util-is-6.0.0.tgz", "resolved": "https://registry.npmmirror.com/unist-util-is/-/unist-util-is-6.0.0.tgz",
+2 -1
View File
@@ -1,5 +1,6 @@
{ {
"devDependencies": { "devDependencies": {
"@types/node": "^18.0.0",
"vitepress": "^1.5.0" "vitepress": "^1.5.0"
}, },
"scripts": { "scripts": {
@@ -7,4 +8,4 @@
"docs:build": "vitepress build", "docs:build": "vitepress build",
"docs:preview": "vitepress preview" "docs:preview": "vitepress preview"
} }
} }
View File
View File