Skip to content

Article pages Table of Contents feature #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

HesitantlyHuman
Copy link

Hi! I'm back again with another feature.

I've implemented a table of contents for the article pages, and figured I'd throw another quick PR, since that is listed on the roadmap.

Features and Changes

  1. Added dynamic table of contents (TOC) which renders from the markdown headings and links to section headings.
  2. Widened the content page to facilitate the width of the TOC and article. Set the TOC to hide when we reach a breakpoint.
  3. Added support for changing the TOC nesting depth on a per article basis, to prevent generation of TOCs which are excessively large.
  4. Added scrolling behavior for TOCs which are too long. The TOC will follow your current page position on scroll, but remains scrollable for navigation purposes. Added simple fade out styling to indicate when the TOC is in a scrolled position, since the scrollbar is hidden unless the TOC is hovered.
  5. Added current position indicator and animation. This animation is generated and rendered client side, so that it can be reactive to page resizing or other content changes.

Known Issues

Because we are using remark-sectionize to wrap our content sections (so that we are able to track our current location in the article) client:load components with inline mdx imports will throw errors, since they are not able to properly locate the import. The simple fix is to do the import at the top of the mdx file, before any markdown headers. While I am personally fine with this fix, I know that this may be inconvenient for some.

Screenshots

Here are some quick screenshots so that you can see how the TOC looks and functions.

image

Here is how it looks on hover

image

If there are no headers, we allow the article to take the full width of the page

image

Simple example without nesting

image

Blog post 4 with nav_depth: 3 has a very long TOC. Here is it following your current position, with the fades

image

HesitantlyHuman and others added 25 commits April 15, 2025 02:14
…rather than hanging to the side because of the TOC
…ize DOM searching and manipulation clientside, update button to copy on mouseup and loose focus on mouseleave
…ment, move TOC to be adjacent to content, revert layouts to old layouts, remove unnecessary content margins, begin TOC tracking implementation, add support for TOC-less article pages
…ssing typing to TOC components, update TOC hiding styling
…ine clamping to TOC links, fix nav sizing issues, add testing blog post
Copy link

vercel bot commented May 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
astro-sphere ❌ Failed (Inspect) May 20, 2025 2:29am

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.

1 participant