diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-07-04 19:14:54 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-07-04 19:14:54 +0900 |
| commit | 80f0ab31aceec35c9fd04a6387b14349b806f713 (patch) | |
| tree | 6d9c3e47fe988f211e8598cbedd2031c09ca54cb /services/blog/nuldoc-src/components/TableOfContents.tsx | |
| parent | 98db243a59fb6a409b3677f2195e96da6fd39564 (diff) | |
| download | nsfisis.dev-80f0ab31aceec35c9fd04a6387b14349b806f713.tar.gz nsfisis.dev-80f0ab31aceec35c9fd04a6387b14349b806f713.tar.zst nsfisis.dev-80f0ab31aceec35c9fd04a6387b14349b806f713.zip | |
feat(blog/nuldoc): implement TOC
Diffstat (limited to 'services/blog/nuldoc-src/components/TableOfContents.tsx')
| -rw-r--r-- | services/blog/nuldoc-src/components/TableOfContents.tsx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/services/blog/nuldoc-src/components/TableOfContents.tsx b/services/blog/nuldoc-src/components/TableOfContents.tsx new file mode 100644 index 00000000..29907d08 --- /dev/null +++ b/services/blog/nuldoc-src/components/TableOfContents.tsx @@ -0,0 +1,33 @@ +import { TocEntry, TocRoot } from "../djot/document.ts"; + +type Props = { + toc: TocRoot; +}; + +export default function TableOfContents({ toc }: Props) { + return ( + <nav className="toc"> + <h2>目次</h2> + <ul> + {toc.entries.map((entry, index) => ( + <TocEntryComponent key={String(index)} entry={entry} /> + ))} + </ul> + </nav> + ); +} + +function TocEntryComponent({ entry }: { entry: TocEntry }) { + return ( + <li> + <a href={`#${entry.id}`}>{entry.text}</a> + {entry.children.length > 0 && ( + <ul> + {entry.children.map((child, index) => ( + <TocEntryComponent key={String(index)} entry={child} /> + ))} + </ul> + )} + </li> + ); +} |
