Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit 6095c3a

Browse files
committed
docs: update to latest clerc api
1 parent 7cb64f2 commit 6095c3a

35 files changed

+1773
-335
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"typescript.tsdk": "node_modules\\typescript\\lib"
2+
"typescript.tsdk": "node_modules\\typescript\\lib",
3+
"files.associations": {
4+
"*.md": "markdown"
5+
}
36
}

docs/.vitepress/config/en.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
import { join } from "node:path";
2+
13
import { defineConfig } from "vitepress";
24

5+
import { getPluginNavigation } from "./plugin-navigation";
6+
7+
const pluginNavigation = await getPluginNavigation(
8+
join(import.meta.dirname, "..", "..", "official-plugins"),
9+
"/official-plugins",
10+
);
11+
312
export const enConfig = defineConfig({
413
lang: "en-US",
514
description: "The The full-featured Command-Line Interface library",
@@ -11,12 +20,12 @@ export const enConfig = defineConfig({
1120
link: "/getting-started",
1221
},
1322
{
14-
text: "Members",
15-
link: "/members",
23+
text: "Official Plugins",
24+
items: pluginNavigation,
1625
},
1726
{
18-
text: "Sponsor (CN)",
19-
link: "https://afdian.net/a/so1ve",
27+
text: "Members",
28+
link: "/members",
2029
},
2130
],
2231
sidebar: [
@@ -35,6 +44,10 @@ export const enConfig = defineConfig({
3544
text: "Interceptors",
3645
link: "/interceptors",
3746
},
47+
{
48+
text: "Context",
49+
link: "/context",
50+
},
3851
{
3952
text: "Plugins",
4053
link: "/plugins",
@@ -43,7 +56,7 @@ export const enConfig = defineConfig({
4356
},
4457
{
4558
text: "Official Plugins",
46-
link: "/official-plugins",
59+
items: pluginNavigation,
4760
},
4861
],
4962
editLink: {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import fs from "node:fs/promises";
2+
import { join } from "node:path";
3+
4+
function extractTitleFromMarkdown(content: string): string | null {
5+
// eslint-disable-next-line regexp/no-super-linear-backtracking
6+
const frontmatterRegex = /^---\s*\n([\s\S]*?)\n---\s*\n/;
7+
const match = content.match(frontmatterRegex);
8+
9+
if (!match) {
10+
return null;
11+
}
12+
13+
const frontmatter = match[1];
14+
// eslint-disable-next-line regexp/no-super-linear-backtracking
15+
const titleRegex = /^title:\s*(.+?)\s*$/m;
16+
const titleMatch = frontmatter.match(titleRegex);
17+
18+
return titleMatch ? titleMatch[1].trim() : null;
19+
}
20+
21+
export async function getPluginTitles(
22+
path: string,
23+
): Promise<{ filename: string; title: string }[]> {
24+
try {
25+
const files = await fs.readdir(path);
26+
const results: { filename: string; title: string }[] = [];
27+
28+
for (const file of files) {
29+
if (file.endsWith(".md")) {
30+
const filePath = join(path, file);
31+
32+
try {
33+
const content = await fs.readFile(filePath, "utf-8");
34+
const title = extractTitleFromMarkdown(content);
35+
36+
if (title) {
37+
results.push({
38+
filename: file,
39+
title,
40+
});
41+
}
42+
} catch (error) {
43+
console.warn(`读取文件 ${file} 时出错:`, error);
44+
}
45+
}
46+
}
47+
48+
results.sort((a, b) => a.filename.localeCompare(b.filename));
49+
50+
return results;
51+
} catch (error) {
52+
console.error(`扫描目录 ${path} 时出错:`, error);
53+
54+
return [];
55+
}
56+
}
57+
58+
export async function getPluginNavigation(
59+
path: string,
60+
webRoot: string,
61+
): Promise<{ text: string; link: string }[]> {
62+
const pluginTitles = await getPluginTitles(path);
63+
64+
return pluginTitles.map(({ filename, title }) => {
65+
const link =
66+
filename === "index.md"
67+
? webRoot
68+
: join(webRoot, filename.replace(/\.md$/, "")).replace(/\\/g, "/");
69+
70+
return {
71+
text: title,
72+
link,
73+
};
74+
});
75+
}

docs/.vitepress/config/zh.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
import { join } from "node:path";
2+
13
import { defineConfig } from "vitepress";
24

5+
import { getPluginNavigation } from "./plugin-navigation";
6+
7+
const pluginNavigation = await getPluginNavigation(
8+
join(import.meta.dirname, "..", "..", "zh", "official-plugins"),
9+
"/zh/official-plugins",
10+
);
11+
312
export const zhConfig = defineConfig({
413
lang: "zh-CN",
514
description: "全功能 CLI 库",
@@ -11,12 +20,12 @@ export const zhConfig = defineConfig({
1120
link: "/zh/getting-started",
1221
},
1322
{
14-
text: "成员",
15-
link: "/zh/members",
23+
text: "官方插件列表",
24+
items: pluginNavigation,
1625
},
1726
{
18-
text: "捐赠作者",
19-
link: "https://afdian.net/a/so1ve",
27+
text: "成员",
28+
link: "/zh/members",
2029
},
2130
],
2231
sidebar: [
@@ -35,15 +44,19 @@ export const zhConfig = defineConfig({
3544
text: "拦截器",
3645
link: "/zh/interceptors",
3746
},
47+
{
48+
text: "上下文",
49+
link: "/zh/context",
50+
},
3851
{
3952
text: "插件",
4053
link: "/zh/plugins",
4154
},
4255
],
4356
},
4457
{
45-
text: "Official Plugins",
46-
link: "/zh/official-plugins",
58+
text: "官方插件列表",
59+
items: pluginNavigation,
4760
},
4861
],
4962
editLink: {

docs/.vitepress/theme/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@
8888
.DocSearch {
8989
--docsearch-primary-color: var(--vp-c-brand) !important;
9090
}
91+
92+
span {
93+
tab-size: 2;
94+
}

0 commit comments

Comments
 (0)