This commit is contained in:
Clas Wen 2025-01-25 21:51:29 +08:00
parent 065b3f2889
commit e84e7ec4b4
8 changed files with 69 additions and 4 deletions

6
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,6 @@
{
"vue.server.includeLanguages": [
"vue",
"markdown"
]
}

View file

@ -1 +1 @@
12
index

View file

@ -9,7 +9,7 @@ type MeetingMinutesParsed = {
link: string
}
const stripFileExtension = (filename: string) => {
export const stripFileExtension = (filename: string) => {
return filename.split(".").slice(0, -1).join(".")
}

View file

@ -18,6 +18,7 @@
},
"dependencies": {
"@types/node": "^22.10.10",
"dayjs": "^1.11.13"
"dayjs": "^1.11.13",
"vue": "^3.5.13"
}
}

View file

@ -14,6 +14,9 @@ importers:
dayjs:
specifier: ^1.11.13
version: 1.11.13
vue:
specifier: ^3.5.13
version: 3.5.13
devDependencies:
vitepress:
specifier: ^1.6.3

15
tsconfig.json Normal file
View file

@ -0,0 +1,15 @@
{
"include": [
"**/*.ts",
"**/*.vue",
"**/*.md",
],
"compilerOptions": {
"esModuleInterop": true
},
"vueCompilerOptions": {
"vitePressExtensions": [
".md"
],
},
}

40
utils/sidebar.test.ts Normal file
View file

@ -0,0 +1,40 @@
import { describe, expect, test, beforeAll, afterAll } from "vitest";
import { scanDir } from "../utils/sidebar";
import { resolve } from "path";
import { mkdtempSync, writeFileSync, rmdirSync } from "fs";
import { tmpdir } from "os";
import { join } from "path";
let tempDir: string;
beforeAll(() => {
tempDir = mkdtempSync(join(tmpdir(), 'test-'));
writeFileSync(join(tempDir, 'test1.md'), '# Test 1');
writeFileSync(join(tempDir, 'test2.md'), '# Test 2');
writeFileSync(join(tempDir, 'test.txt'), 'Test text file');
});
afterAll(() => {
rmdirSync(tempDir, { recursive: true });
});
describe("scanDir", () => {
test("should return markdown files with correct structure", () => {
const res = scanDir(tempDir);
expect(res).toBeInstanceOf(Array);
expect(res.length).toBe(2);
res.forEach(item => {
expect(item).toHaveProperty("filename");
expect(item).toHaveProperty("link");
expect(item.filename).toMatch(/\.md$/);
expect(item.link).toBe(resolve(tempDir, item.filename));
});
});
test("should return an empty array if no markdown files are found", () => {
const emptyDir = mkdtempSync(join(tmpdir(), 'empty-'));
const res = scanDir(emptyDir);
expect(res).toEqual([]);
rmdirSync(emptyDir, { recursive: true });
});
});

View file

@ -10,7 +10,7 @@ export const scanDir = (dirname: string) => {
return markdownFileNames.map(v => {
return {
filename: v,
link: path.join(dirpath, v)
link: path.join(dirname, v)
}
})
}