fix: heading
This commit is contained in:
parent
c923d80d30
commit
53faa775be
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, createSignal, onMount, Show } from "solid-js";
|
import { Component, createMemo, createSignal, onMount, Show } from "solid-js";
|
||||||
import { generateToc, type FileNode, type TocNode } from "../data-loader";
|
import { generateToc, type FileNode, type TocNode } from "../data-loader";
|
||||||
import { useLocation } from "@solidjs/router";
|
import { useLocation } from "@solidjs/router";
|
||||||
import { FileTreeNode, HeadingNode } from "./FileTree";
|
import { FileTreeNode, HeadingNode } from "./FileTree";
|
||||||
|
|
@ -17,25 +17,18 @@ export const Sidebar: Component<SidebarProps> = (props) => {
|
||||||
const [pathHeadings, setPathHeadings] = createSignal<
|
const [pathHeadings, setPathHeadings] = createSignal<
|
||||||
Record<string, TocNode[]>
|
Record<string, TocNode[]>
|
||||||
>({});
|
>({});
|
||||||
const [currentFileHeadings, setCurrentFileHeadings] = createSignal<TocNode[]>(
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// 加载目录数据
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const toc = await generateToc();
|
const toc = await generateToc();
|
||||||
setFileTree(toc.fileTree);
|
setFileTree(toc.fileTree);
|
||||||
setPathHeadings(toc.pathHeadings);
|
setPathHeadings(toc.pathHeadings);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 根据当前路径更新当前文件的标题列表
|
// 响应式获取当前文件的标题列表
|
||||||
onMount(() => {
|
const currentFileHeadings = createMemo(() => {
|
||||||
const updateHeadings = () => {
|
const pathname = location.pathname;
|
||||||
const pathname = location.pathname;
|
return pathHeadings()[pathname] || pathHeadings()[`${pathname}.md`] || [];
|
||||||
const headings =
|
|
||||||
pathHeadings()[pathname] || pathHeadings()[`${pathname}.md`];
|
|
||||||
setCurrentFileHeadings(headings || []);
|
|
||||||
};
|
|
||||||
updateHeadings();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue