How to add headings injected from a layout component #1366
Replies: 1 comment 1 reply
-
Thanks for the post @KonnorRogers! This is currently not supported using Theoretically, one way you could work around it for your use case though would be to override Starlight’s ---
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/PageSidebar.astro';
if (shouldAddSlotsHeading) {
Astro.props.toc.items = [
...Astro.props.toc.items,
{ depth: 2, slug: 'slots', text: 'Slots', children: [] },
];
}
---
<Default {...Astro.props}><slot /></Default> Gets trickier if you need to splice it somewhere in the middle or have actual page headings as children though, so I guess YMMV. Otherwise, the pattern I tend to use in cases like this is to avoid a layout and use a component in MDX instead to wrap the extra stuff when needed and include the |
Beta Was this translation helpful? Give feedback.
-
What version of
starlight
are you using?0.15.1
What is your idea?
If I'm writing a markdown layout, I would like any additional
<h*>
tags to be added to the TOC. (not sure if this is a discussion or an issue)Why is this feature necessary?
It allows dynamically injecting markup without needing to write
.mdx
files directly and wrapping in a component.Do you have examples of this feature in other projects?
Markdown file:
Component Layout File:
I would expect
<h2 id="slots">
to be added to the TOC in StarlightParticipation
Beta Was this translation helpful? Give feedback.
All reactions