I wanna override the TableOfContents different on some pages / routes, where different global styling is applied that conflicts with each other:
The override:
---
import Default from '@astrojs/starlight/components/TableOfContents.astro'
import BottomTableOfContentWrapper from 'starlight-cooler-credit/components/BottomTableOfContentWrapper.astro'
import TopTableOfContentWrapper from 'starlight-cooler-credit/components/TopTableOfContentWrapper.astro'
import DefaultBottomTableOfContentWrapper from 'starlight-cooler-credit/components/DefaultBottomTableOfContentWrapper.astro'
const currentPath = Astro.url.pathname;
const showBottomTable = currentPath.includes('bottom-table-of-content-wrapper');
const showTopTable = currentPath.includes('top-table-of-content-wrapper');
---
{showBottomTable ? (
<Default><slot /></Default>
<BottomTableOfContentWrapper>
<p>Hello, Astronaut! 👨🚀</p>
</BottomTableOfContentWrapper>
) : showTopTable ? (
<TopTableOfContentWrapper>
<p>✨ Reaching for the stars! ✨</p>
</TopTableOfContentWrapper>
<Default><slot /></Default>
) : (
<Default><slot /></Default>
<DefaultBottomTableOfContentWrapper />
)}
In BottomTableOfContentWrapper I make the right-sidebar-panel display: flex; and in TopTableOfContentWrapper I make it display: block;
Because Astro is a static site generator, both styles are existing even when not on any of those routes, making the sidebar look wrong...
It's important that the structure of the overrides don't change because it's a Starlight plugin which should only simple stuff.
I can provide the code of the Top/BottomTableOfContentWrappers if you want!