-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
page loaders #1216
page loaders #1216
Conversation
We could maybe call this “page generator” (and “generated pages”) instead. |
Yay, I wanted to explore something like this too. In my idea (that I hadn't really tried to implement yet) parseMarkdown would have been one of the input helpers, instead of something that is applied by default to all (transformed) pages. In order to outline some design considerations: my idea was something like this:
Whereas this PR treats md as the pivot format:
The only advantage to my approach is that the generated page wouldn't go through markdown at all if your input format was not md, thus making sure there are no surprises after your page generator has run. (However, outputting html with no line breaks should guarantee that too.) This PR's approach is much better:
|
Indeed that was my original plan which you can see in the first commit, and I’d still like to support that, too — particularly for JSX which is compiled to JavaScript that needs to be evaluated on the server and then serializes to HTML. I was originally thinking of generating JSON using the |
Now that we’ve landed JSX and React separately #1429, I want to reboot this PR to focus just on page loaders. I want to stick with Markdown as the serialized representation of the page for now. We do need a serialized representation because we want to be able to write page loaders in other languages (e.g., |
334f74c
to
3f949b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As part of this work, I refactored the data loaders implementation a bit. Instead of an Asset
interface, I made a StaticLoader
implementation of the Loader
interface; this means that downstream consumers of loaders don’t have to care whether a file is static or generated dynamically by a loader. (No "load" in loader
test.) I also changed loader.path
so that it is relative to the source root rather than relative to the current working directory, which felt more consistent.
Rebooted this PR. I marked this as ready for review since I’m planning on merging it into the parent parameterized routing PR and landing both together. Both are close to ready — mostly needing documentation and tests, and porting the theme previews over to parameterized page loaders. |
A page loader is like a data loader, but for pages instead of files or assets: it allows you to generate Markdown dynamically (at build time) rather than being limited to static Markdown. Page loaders allow server-side rendering #931 and are particularly useful in conjunction with parameterized pages #1523.
(Unlike earlier versions of this PR, this implementation is still Markdown-specific. In the future, we can explore authoring pages in HTML instead of Markdown if desired, but this should be treated as an orthogonal problem.)
TODO
generate-themes
scriptFixes #931.