mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-05-18 14:34:23 +02:00
Compare commits
3 Commits
08717394ff
...
26ff78f81f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
26ff78f81f | ||
![]() |
0cacd48458 | ||
![]() |
51790b3926 |
@ -16,7 +16,7 @@
|
|||||||
"docs": "npx quartz build --serve -d docs",
|
"docs": "npx quartz build --serve -d docs",
|
||||||
"check": "tsc --noEmit && npx prettier . --check",
|
"check": "tsc --noEmit && npx prettier . --check",
|
||||||
"format": "npx prettier . --write",
|
"format": "npx prettier . --write",
|
||||||
"test": "for f in $(find ./quartz -name '*.test.ts'); do tsx $f; done",
|
"test": "tsx --test",
|
||||||
"profile": "0x -D prof ./quartz/bootstrap-cli.mjs build --concurrency=1"
|
"profile": "0x -D prof ./quartz/bootstrap-cli.mjs build --concurrency=1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
@ -127,19 +127,20 @@ describe("FileTrie", () => {
|
|||||||
describe("entries", () => {
|
describe("entries", () => {
|
||||||
test("should return all entries", () => {
|
test("should return all entries", () => {
|
||||||
const data1 = { title: "Test1", slug: "test1" }
|
const data1 = { title: "Test1", slug: "test1" }
|
||||||
const data2 = { title: "Test2", slug: "test2" }
|
const data2 = { title: "Test2", slug: "a/b/test2" }
|
||||||
|
|
||||||
trie.add(data1)
|
trie.add(data1)
|
||||||
trie.add(data2)
|
trie.add(data2)
|
||||||
|
|
||||||
const entries = trie.entries()
|
const entries = trie.entries()
|
||||||
assert.strictEqual(entries.length, 3)
|
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
entries.map(([path, node]) => [path, node.data]),
|
entries.map(([path, node]) => [path, node.data]),
|
||||||
[
|
[
|
||||||
["", trie.data],
|
["", trie.data],
|
||||||
["test1/index", data1],
|
["test1", data1],
|
||||||
["test2/index", data2],
|
["a/index", null],
|
||||||
|
["a/b/index", null],
|
||||||
|
["a/b/test2", data2],
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -165,7 +166,7 @@ describe("FileTrie", () => {
|
|||||||
trie.add(data3)
|
trie.add(data3)
|
||||||
const paths = trie.getFolderPaths()
|
const paths = trie.getFolderPaths()
|
||||||
|
|
||||||
assert.deepStrictEqual(paths, ["folder", "folder/subfolder", "abc"])
|
assert.deepStrictEqual(paths, ["folder/index", "folder/subfolder/index", "abc/index"])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -103,12 +103,13 @@ export class FileTrieNode<T extends FileTrieData = ContentDetails> {
|
|||||||
currentPath: string,
|
currentPath: string,
|
||||||
): [FullSlug, FileTrieNode<T>][] => {
|
): [FullSlug, FileTrieNode<T>][] => {
|
||||||
const segments = [currentPath, node.slugSegment]
|
const segments = [currentPath, node.slugSegment]
|
||||||
if (node.isFolder && node.depth > 0) {
|
|
||||||
segments.push("index")
|
|
||||||
}
|
|
||||||
|
|
||||||
const fullPath = joinSegments(...segments) as FullSlug
|
const fullPath = joinSegments(...segments) as FullSlug
|
||||||
const result: [FullSlug, FileTrieNode<T>][] = [[fullPath, node]]
|
|
||||||
|
const indexQualifiedPath =
|
||||||
|
node.isFolder && node.depth > 0 ? (joinSegments(fullPath, "index") as FullSlug) : fullPath
|
||||||
|
|
||||||
|
const result: [FullSlug, FileTrieNode<T>][] = [[indexQualifiedPath, node]]
|
||||||
|
|
||||||
return result.concat(...node.children.map((child) => traverse(child, fullPath)))
|
return result.concat(...node.children.map((child) => traverse(child, fullPath)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user