--- import { isSelfNumbered } from '../lib/rehype-heading-marks.mjs'; interface Heading { depth: number; slug: string; text: string; } interface Props { headings: Heading[]; /** Number the sections, matching the numbers the article's own headings * carry. Only the hand-authored sheets do (rehype-heading-marks); the * mirrors keep their headings as written, so their rail stays unnumbered. */ numbered?: boolean; } const { headings, numbered = false } = Astro.props; /** * "On this page": the contents rail beside every article, and the same node * folded into a disclosure above it on a narrow screen. One element serves * both so the scroll-spy in app.ts (`initTOC`) has a single set of links. * Styling is in global.css (`.toc`) with the layout it sits in. */ const toc = headings.filter((h) => h.depth === 2 || h.depth === 3); const sections = toc.filter((h) => h.depth === 2); // The same test the heading pass applies, on the same titles, so a sheet // that numbers its own sections is left alone in both places. const showNumbers = numbered && sections.length > 0 && !isSelfNumbered(sections.map((h) => h.text)); let n = 0; const items = toc.map((h) => ({ ...h, n: h.depth === 2 ? String(++n).padStart(2, '0') : '' })); --- {toc.length > 1 && (
On this page {String(sections.length || toc.length).padStart(2, '0')}
)}