Generalize getStaticPaths() into setup() for every page #78
Replies: 2 comments 5 replies
-
I really like this direction! I've been working on a few ideas related to building pages that are fully managed in a CMS, ending up looking a lot like the building every page from
Thoughts on also exposing the pagination helper here as well? I'm not sure exactly what that'd look like at the moment, but being able to use pagination to have
I really like the idea of automatically caching network requests based on cache headers, but I'm a little torn on building that directly into This might be more confusing than helpful, but could we somehow make an API that mimics a ServiceWorker since that's really what this would be doing? It would end up being opt-in, which might make it more clear why |
Beta Was this translation helpful? Give feedback.
-
11ty has a newer (I think) API, |
Beta Was this translation helpful? Give feedback.
-
My for-fun thinking project for the weekend: Revisiting frontmatter scoping. I ultimately didn't get anywhere better than what we currently have (it turns out that the current component-scoped frontmatter is pretty dang useful!). However, I do have one suggestion for an improvement that I think will solve a few smaller issues for us.
Summary
Introduce a
setup()
function that any component can use to run expensive, one-time setup work.Example - A place for expensive, one-time work
Example - replaces
getStaticPaths()
Example - adds
rss()
support to every page (not just getStaticPaths)Alternative - data
Instead of an explicit
setData()
function for data-passing outside of the setup() function, you could also create an implicit system where you just set the data ontoAstro.data
directly:Note on
fetch()
I believe that there is already buy-in for
fetch()
to respect cache headers similar to the browser. I bring this up because that means that fetch() wouldn't need to go into setup() - it could get called on every render and just return the cached value.setup()
would only be needed for other kinds of expensive or one-time work, like a DB call.This doesn't prevent us from exploring more one-off caching/memoization around a single variable in the frontmatter.
Beta Was this translation helpful? Give feedback.
All reactions