Skip to content

Add Table of Contents for posts#137

Open
eXpl0it3r wants to merge 1 commit into
Zuehlke:mainfrom
eXpl0it3r:feature/table-of-contents
Open

Add Table of Contents for posts#137
eXpl0it3r wants to merge 1 commit into
Zuehlke:mainfrom
eXpl0it3r:feature/table-of-contents

Conversation

@eXpl0it3r
Copy link
Copy Markdown
Contributor

@eXpl0it3r eXpl0it3r commented Nov 26, 2025

Closes #123

Using rehype slug & autolink-headings & toc we can automatically add a Table of Contents to every blog post.

I marked this as draft, as I feel like it could use some more work:

  • Make more use of Tailwind CSS instead of custom CSS
  • Reduce the size of the Astro config somehow
  • Fix the syntax issues with rehype-toc (not sure why VS Code marks it as error)

Not sure if/when I have the time to fix this, but the draft PR could also just serve as inspiration for someone else.

Desktop view

image

Responsive "tablet" / mobile view

image

Comment thread astro.config.mjs Outdated
Copy link
Copy Markdown

@kunman93 kunman93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good foundation! The TOC feature works end-to-end and the responsive sidebar layout is a nice touch. A few things to address before this is ready:

Functional issues

  • The convertToUl hast mutation is redundant — the CSS .toc-sidebar ol { list-style: none } already handles this visually, and removing the JS conversion makes that CSS rule live again (see inline comments).
  • h1 is included in the heading list but article bodies almost certainly don't use # h1, so removing it avoids surprising TOC entries.
  • The <nav> created by customizeTOC is missing an aria-label, which breaks accessibility when more than one <nav> is on the page.

CSS

  • There is a ~160px gap between the max-width: 1279px (mobile) and min-width: 90rem (1440px desktop) breakpoints where neither layout rule fires.

Minor

  • Indentation inside rehypePlugins is inconsistent with the rest of the config.
  • mb-16 removal affects posts without headings (no TOC rendered), which may look odd.

The VS Code TypeScript error you mentioned is likely caused by rehype-toc being a thin re-export of @jsdevtools/rehype-toc without proper ESM type declarations. You could suppress it with // @ts-ignore above the import, or switch to importing @jsdevtools/rehype-toc directly (it's already installed as a transitive dependency).

Comment thread astro.config.mjs Outdated
Comment thread astro.config.mjs Outdated
Comment thread astro.config.mjs Outdated
Comment thread astro.config.mjs Outdated
Comment thread src/styles/global.css
Comment thread src/styles/global.css Outdated
Comment thread src/pages/[slug].astro Outdated
@eXpl0it3r eXpl0it3r force-pushed the feature/table-of-contents branch from 706a1d7 to 2e0dd67 Compare May 8, 2026 18:32
@eXpl0it3r eXpl0it3r requested a review from kunman93 May 8, 2026 20:07
@eXpl0it3r eXpl0it3r marked this pull request as ready for review May 8, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table Of Contents

2 participants