Compare commits

..

No commits in common. "26ff78f81f9a630a85710c920ae532c98bb349d8" and "08717394ff851af1513516223bd255ef7f9cda3d" have entirely different histories.

3 changed files with 11 additions and 13 deletions

View File

@ -16,7 +16,7 @@
"docs": "npx quartz build --serve -d docs",
"check": "tsc --noEmit && npx prettier . --check",
"format": "npx prettier . --write",
"test": "tsx --test",
"test": "for f in $(find ./quartz -name '*.test.ts'); do tsx $f; done",
"profile": "0x -D prof ./quartz/bootstrap-cli.mjs build --concurrency=1"
},
"engines": {

View File

@ -127,20 +127,19 @@ describe("FileTrie", () => {
describe("entries", () => {
test("should return all entries", () => {
const data1 = { title: "Test1", slug: "test1" }
const data2 = { title: "Test2", slug: "a/b/test2" }
const data2 = { title: "Test2", slug: "test2" }
trie.add(data1)
trie.add(data2)
const entries = trie.entries()
assert.strictEqual(entries.length, 3)
assert.deepStrictEqual(
entries.map(([path, node]) => [path, node.data]),
[
["", trie.data],
["test1", data1],
["a/index", null],
["a/b/index", null],
["a/b/test2", data2],
["test1/index", data1],
["test2/index", data2],
],
)
})
@ -166,7 +165,7 @@ describe("FileTrie", () => {
trie.add(data3)
const paths = trie.getFolderPaths()
assert.deepStrictEqual(paths, ["folder/index", "folder/subfolder/index", "abc/index"])
assert.deepStrictEqual(paths, ["folder", "folder/subfolder", "abc"])
})
})

View File

@ -103,13 +103,12 @@ export class FileTrieNode<T extends FileTrieData = ContentDetails> {
currentPath: string,
): [FullSlug, FileTrieNode<T>][] => {
const segments = [currentPath, node.slugSegment]
if (node.isFolder && node.depth > 0) {
segments.push("index")
}
const fullPath = joinSegments(...segments) as FullSlug
const indexQualifiedPath =
node.isFolder && node.depth > 0 ? (joinSegments(fullPath, "index") as FullSlug) : fullPath
const result: [FullSlug, FileTrieNode<T>][] = [[indexQualifiedPath, node]]
const result: [FullSlug, FileTrieNode<T>][] = [[fullPath, node]]
return result.concat(...node.children.map((child) => traverse(child, fullPath)))
}