import { Component, createMemo, createSignal, onMount, Show } from "solid-js"; import { generateToc, type FileNode, type TocNode } from "../data-loader"; import { useLocation } from "@solidjs/router"; import { FileTreeNode, HeadingNode } from "./FileTree"; interface SidebarProps { isOpen: boolean; onClose: () => void; } /** * 侧边栏组件 */ export const Sidebar: Component = (props) => { const location = useLocation(); const [fileTree, setFileTree] = createSignal([]); const [pathHeadings, setPathHeadings] = createSignal< Record >({}); // 加载目录数据 onMount(async () => { const toc = await generateToc(); setFileTree(toc.fileTree); setPathHeadings(toc.pathHeadings); }); // 响应式获取当前文件的标题列表 const currentFileHeadings = createMemo(() => { const pathname = location.pathname; return pathHeadings()[pathname] || pathHeadings()[`${pathname}.md`] || []; }); return ( <> {/* 遮罩层 */}
{/* 侧边栏 */} ); };