Improve custom page injection #982
Replies: 3 comments 1 reply
-
Linking withastro/roadmap#688 here too as it’s kind of related. |
Beta Was this translation helpful? Give feedback.
-
I have been trying out various approaches to this issue so posting an update with my findings so far. We briefly mentioned the idea of exposing One thing I noticed, still in this specific context, is that from Considering this, I have been thinking about 2 approaches: Note: all names are just for the sake of the example (and I could not find something I like which is properly describing what this does) and should be discussed if we go with one of these approaches. A new componentA component like type Props = Omit<PageProps, "sidebar" | "hasSidebar">; This would be used like the existing ---
const { pagination, ...props } = Astro.props;
const sidebar = getSidebar(Astro.url.pathname, props.locale);
---
<Page
{...props}
hasSidebar
sidebar={sidebar}
pagination={pagination ?? getPrevNextLinks(sidebar, config.pagination, props.entry.data)}
>
<slot />
</Page> If we were to add more data to A new helperA new exposed helper function like The code would be pretty much identical to the one described above and an integration injecting a new route would call this before rendering the built-in Note: this could even exists with the component approach (but not exposed) and used in that component and internally too to ensure everything is always in-sync between the internals props and the exposed component. ThoughtsSo far I have not been able to find a better approach than these 2. I am still not sure if there is a better way to do this, if I am missing something obvious or if we should go with one of these approaches. This is personally one of my main issue in Starlight at the moment that I would love to see properly solved so if anyone has any thoughts on this, please feel free to share them. |
Beta Was this translation helpful? Give feedback.
-
Closing this feature request as the |
Beta Was this translation helpful? Give feedback.
-
What version of
starlight
are you using?0.11.1
What is your idea?
Enable custom page injection while still being able to use the default generated route data.
Why is this feature necessary?
This discussion is a follow-up of #861.
An Astro integration injecting a custom route using
injectRoute()
cannot use Starlight design (e.g. by rendering<Page/>
) while still being able to use some of the data generated by Starlight (e.g. the sidebar content).Reusing the same data generated by Starlight is useful in some cases, for example
starlight-openapi
which injects new routes to render OpenAPI endpoints documentation but does not need to override the default sidebar content.Various solutions have already been talked about:
generateRouteData()
injectPage()
API avalailable through a plugin hookDo you have examples of this feature in other projects?
No response
Participation
Beta Was this translation helpful? Give feedback.
All reactions