Content as Data v2 #1286
Replies: 1 comment 2 replies
-
As we've discussed in discord, I've been looking at migrating from Astro to Greenwood since Astro has deprecated support for Lit element based components. One of the features of Astro that I currently use fairly heavily is its data type content collections. I use these to read in collections of yaml and json files, with each directly of files being instances of the same data structure. In Astro, the resulting data content collection thus ends up being a convenient hash/map from which I can access one or more instances in a variety of different elements. The collection is thus not mapping to a route/page, as each data collection is used in at at least two different lit elements, each of which occurs (sometimes more than once) on at least two different pages. One of these I use to draw an element that contains a variety of details about a fictional character's biography. It uses a child component that displays a formatted name 3 or 4 times. A different page in the same project uses the same content collection to display information about the family (as opposed to the individual). In a different project, I have a content collection that is used by components in one route to display details of individual generals, matching on the [id] parameter in the route. In another place, a static page has a table component in it that pulls in details from the same content collection of generals to allow for side by side comparison within the table. As you can see the data content collections are, as you aptly summarized in discord, generics that allow me to avoid writing custom importers similar to
that for each individual data collection. Such a custom importer would have several downsides:
Of these the second and third are obviously more important. |
Beta Was this translation helpful? Give feedback.
-
Overview
Coming out of #1167 / #1266, wanted to track a few thoughts / questions / outstanding items that I didn't have a good answer for at the time, and so wanted to carryover into a discussion for further refining / iteration.
Carryovers
Active Frontmatter
The current API for templating out frontmatter at build time is to use this convention of combining template literal syntax and
globalThis
.I suppose something more "traditional" might be something like handlebars, etc
Maybe it doesn't matter since it's all implementation details, but the convention could literally be anything really, but it just has to be super unique. Not sure how others feel about this technical design or maybe it's just fine? 🤷♂️
Content ("Server") APIs
To support our content APIs, e.g.
Wondering if there is a better way to execute / expose this API? The main issue is that it has to rely on isomorphic APIs, and
fetch
is just that kind of API, in particular for prerendering scenarios at build time, where we spin up an instance of the dev server with just the content as data plugin configured.One thought was that at least for production builds, we could each inline query into a
<script>
tag into the HTML? This would avoid having to do afetch
if the data was desired on the client side as well even with a production build.We would have to be able to trace queries to pages, so as not to bloat the HTML for every page with every query. (which I think is what prevents us from completing #349)
"Noisy" Active Frontmatter
In cases where you would say want to serialize a collection into HTML is a little "noisy" due to all the properties of the graph being part of the out, with a lot items in your collection could potentially add a lot of extra content to the HTML
We are already pruning a lot of it, but maybe we could strip out the attribute? That would be bad though if someone was trying to hydrate off of it on the client side.
Naming (Graph)
I wonder if there is a case to rename
graph
topages
instead? A graph implies nodes, some sort of linking structure, etc which it is definitely not in its current state.While we're on naming, should our
compilation.context
directories have their names changed too,outputDir
->outputDirUrl
scratchDir
->scratchDirUrl
optimizedFileName
Standalone Plugin
Since I know we plan on moving Markdown to its own plugin, should this be standalone too? One consideration is that if user's don't like the "native" implementation, they could basically just never enable the
activeContent
flag and write their own plugin / resolvers / etc.Beta Was this translation helpful? Give feedback.
All reactions