One thing I'm thinking about right now is changing generateFiles
to have access to StaticHttp.Request
data.
I'm feeling pretty good about that direction because you can share StaticHttp.Request
s by just extracting them in your Elm code. For example, you might have:
type alias Event = { title : String, {- ... -} }
Event.staticRequest : StaticHttp.Request (List Event)
Then re-use the same one in generateFiles
, or in your view
function for specific pages (or all pages).
One interesting thing about StaticHttp.Request
s in the context of generateFiles
is that the raw responses don't end up in your final bundle, only the resulting files that are generated. So there's no need to make optimized requests there (so if you wanted to do StaticHttp.unoptimizedRequest
in that context, it wouldn't be any different).
Access to StaticHttp.Request
data for static results
There are currently 2 other places where we can just use StaticHttp.Request
s as a helper to fetch data to get your final results, but the responses are not bundled into your data, only the final result is.
Pages.Platform.application {
- ...
, canonicalSiteUrl : String
, manifest : Pages.Manifest.Config pathKey
, generateFiles :
List
{ path : PagePath pathKey
, frontmatter : metadata
, body : String
}
-> List (Result String { path : List String, content : String })
}
So giving these access to StaticHttp data could look like this.
Pages.Platform.application {
- ...
, canonicalSiteUrl : StaticHttp.Request String
, manifest : StaticHttp.Request (Pages.Manifest.Config pathKey)
, generateFiles :
List
{ path : PagePath pathKey
, frontmatter : metadata
, body : String
}
->
StaticHttp.Request (List
(Result String { path : List String, content : String })
)
}
Access to StaticHttp
data in more dynamic places
I think it makes sense to have access to StaticHttp
data in dynamic places.
It could be in init
, or in update
, or in onPageChange
(or some combination). A few things to consider:
init
is called for all pages, so any StaticHttp.Request
s in that context would be global data (need to download for any page you visit, whether it's used there or not)
Giving onPageChange
access to StaticHttp.Request
data
If we give onPageChange
access to StaticHttp
data, then you can access data for a specific page (and potentially fetch different data based on the PagePath and the page's metadata)
We would also need to change the arguments so that you don't have access to the query
and fragment
when you make the StaticHttp.Request
, since that's dynamic and not known at build-time.
Currently, this is the function signature:
, onPageChange :
{ path : PagePath pathKey
, query : Maybe String
, fragment : Maybe String
}
Giving input
This is an early stage idea and I'm still doing some thinking on the design. Ideas and use cases are welcome!
I'm also going to be working on a builder-style way to add to your Pages.Platform.application
config to build it, adding one piece at a time. So that design could work nicely with adding StaticHttp
data in more places because we could have helpers for building that have StaticHttp
data, or that don't.