fix(sidebar): add correct node identity to heading set
This commit is contained in:
@@ -35,29 +35,14 @@ const SidebarContent: Component<SidebarContentProps> = (props) => {
|
||||
props.pathHeadings[pathname] || props.pathHeadings[`${pathname}.md`] || []
|
||||
);
|
||||
});
|
||||
const revealedHeadings = createMemo(() => {
|
||||
const pathname = decodeURIComponent(location.pathname);
|
||||
const set = new Set<string>();
|
||||
function traverse(node: TocNode, cb: (node: TocNode) => void) {
|
||||
cb(node);
|
||||
node.children?.forEach((child) => traverse(child, cb));
|
||||
}
|
||||
for (const node of currentFileHeadings()) {
|
||||
traverse(node, (anode) => {
|
||||
if (isPathRevealed(pathname, anode.id ?? anode.title)) {
|
||||
traverse(anode, (each) => set.add(anode.id ?? anode.title));
|
||||
}
|
||||
});
|
||||
}
|
||||
return set;
|
||||
});
|
||||
const isFileHidden = (node: FileNode): boolean => {
|
||||
if (isPathRevealed(node.path)) return false;
|
||||
if (node.children?.some((child) => !isFileHidden(child))) return false;
|
||||
return true;
|
||||
};
|
||||
const isHeadingHidden = (node: TocNode): boolean => {
|
||||
if (revealedHeadings().has(node.id ?? node.title)) return false;
|
||||
const pathname = decodeURIComponent(location.pathname);
|
||||
if (isPathRevealed(pathname, node.id ?? node.title)) return false;
|
||||
if (node.children?.some((child) => !isHeadingHidden(child))) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user