Skip to content

Commit d9fd33f

Browse files
committed
perf: add config json
1 parent 4b561dc commit d9fd33f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

docs/.vitepress/plugins/mirror.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,35 @@ async function* traverseDirectory(
102102

103103
export const buildEnd = async () => {
104104
if (!useMirror) return;
105-
for await (const filePathName of traverseDirectory(
106-
process.cwd() + '/.vitepress/dist',
107-
)) {
105+
const baseDir = posixPath(process.cwd() + '/.vitepress/dist');
106+
const relativePath = (v: string) => {
107+
return v.substring(baseDir.length);
108+
};
109+
const htmlUrlMap: Record<string, string> = {};
110+
for await (const filePathName of traverseDirectory(baseDir)) {
108111
if (filePathName.endsWith('.html')) {
109-
const textFileName = filePathName + '.txt';
112+
const textFileName = filePathName + '.md';
110113
await fs.copyFile(filePathName, textFileName);
114+
htmlUrlMap[relativePath(filePathName)] = relativePath(textFileName);
111115
}
112116
}
117+
Object.keys(htmlUrlMap).forEach((k) => {
118+
if (k.endsWith('/index.html')) {
119+
htmlUrlMap[k.replace(/index\.html$/, '')] = htmlUrlMap[k];
120+
} else if (k.endsWith('.html')) {
121+
htmlUrlMap[k.replace(/\.html$/, '')] = htmlUrlMap[k];
122+
}
123+
});
124+
await fs.writeFile(
125+
baseDir + '/_config.json',
126+
JSON.stringify(
127+
{
128+
htmlUrlMap,
129+
},
130+
undefined,
131+
2,
132+
),
133+
);
113134
};
114135

115136
const Parser =

0 commit comments

Comments
 (0)