challenges

MDX Table of Contents: Part 2

In this workshop, you’ll create a (non-interactive) “table of contents” display.

You can work by using the resources at the bottom of this page only (and your own research and skills), or by looking at the hints – or even by visiting the solution page and then going back and writing the code from memory.

Workshop context

Your goals

By the end of this workshop:

The end result should look approximately like this, but it’s fine if yours isn’t a “pixel perfect” rendition.

blog post with a table of contents on the right

Hints

Hint 1 I added a new ToC.tsx and ToC.module.css file within src/components/BlogPost. Why didn’t these get their own ToC folder? The ToC component is never going to be used outside BlogPost, so according to Josh W. Comeau’s recommended file structure , these don’t need to be exposed to the rest of the application.

Hint 2 You can find CSS custom properties for the site’s colors in src/app/globals.css .

Hint 3 I used a CSS Grid and grid areas to place the table of contents below the BlogHero and alongside the content.

Resources