Replies: 6 comments 1 reply
-
|
I can totally see this being useful |
Beta Was this translation helpful? Give feedback.
-
|
I really like this idea! It could benefit one of the most common use cases for astro - rendering from a headless CMS. If an integration can take control of making the API calls, it can also be smart about caching them - potentially saving several minutes from each build. |
Beta Was this translation helpful? Give feedback.
-
|
Adding a note from chatting with @matthewp earlier today: One challenge could be HMR: during dev an integration might need to use |
Beta Was this translation helpful? Give feedback.
-
|
I originally posted here withastro/starlight#962 (comment) and found this discussion based on the responses I got. So I try to add my feedback here too, to outline usecases.
Yes. My first step was just doing plain astro pages and dynamic routes. This technically works but I struggle to get that into the Starlight layout.
Additionally I'd like to add a special "hybrid API-document-merge approach":
I already solved this hybrid-merge-approach with the full astrojs power (
Once at startup would be great, since in our use case we fetch all the data we need in one large batch. |
Beta Was this translation helpful? Give feedback.
-
|
I like this idea a lot! |
Beta Was this translation helpful? Give feedback.
-
|
I think most of the ideas here will likely end up being covered by #946 so going to close this one in favour of that! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Summary
Content collections currently support on-disk files. This proposal suggests an API for adding collection entries programmatically.
Background & Motivation
Content collections offer a powerful way to use content in Astro and associate strongly typed metadata with each piece of content via Markdown frontmatter. This makes it easy to build tools that can flexibly render user content based on its structured data. Currently, this is limited to content that lives on disk in the
src/content/directory of a repo.As we’ve built Starlight we’ve seen users like the general experience of working this way, but several have expressed a desire to add pages from additional sources to Starlight sites. For example:
Historically, we’ve solved many of these cases with dynamic routes in a project or
injectRoutefor an integration. However, for a project like Starlight where frontmatter is used to build site navigation, make layout decisions, etc. those tools place content “out of sight” for the framework. An API for adding entries to a content collection programmatically would support something similar toinjectRoutebut specifically for structured content and metadata.Goals
Example
There are lot of fairly complex technical considerations around how to implement this, but I’m currently imagining an integration hook similar to
injectRoute()likeinjectContent(). There may be a question of whether the code should run on dev server start or be evaluated lazily when a collection is used. Showing a callback style here for the latter case.Not going to go into too much more detail for now, but imagine the callback could be
asyncfor file system or network operations.During build the callback would need to be evaluated while building static endpoints and the result bundled for SSR, I guess? Don’t know if that’s an acceptable design, but it aligns with the static-build behaviour of content collections currently. Very much open to other suggestions.
This could also take a form closer to
injectRoutewhere instead of an inline callback, the integration provides a path to a module that contains the logic for loading content entries, i.e.injectContent('docs', './get-docs.ts').Beta Was this translation helpful? Give feedback.
All reactions