fix(folder): use memoized trie instead of handrolled path solution (closes #1767)

This commit is contained in:
Jacky Zhao
2025-03-14 15:08:23 -07:00
parent da1b6b37fe
commit fbb4523853
5 changed files with 144 additions and 42 deletions

View File

@ -89,6 +89,14 @@ export class FileTrieNode<T extends FileTrieData = ContentDetails> {
this.insert(file.slug.split("/"), file)
}
findNode(path: string[]): FileTrieNode<T> | undefined {
if (path.length === 0 || (path.length === 1 && path[0] === "index")) {
return this
}
return this.children.find((c) => c.slugSegment === path[0])?.findNode(path.slice(1))
}
/**
* Filter trie nodes. Behaves similar to `Array.prototype.filter()`, but modifies tree in place
*/