-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pass collection context to mustache #34
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The context is not fed to mustache yet, this will be done in a follow-up commit. This commit also includes cleanup around how paths are determined. There is one minor breaking change: the third attribute that was passed to a custom buildScript, the current page's slug, used to omit the trailing slash. It now includes it, for consistency.
BREAKING CHANGE: the mustache view changed from frontmatter `{ [key]: value }` to `{ page: { frontmatter: { [key]: value } }, context: { pages: Page[] } }`. Where a template was referencing the frontmatter `title` via `{{title}}`, it now needs to be referenced as `{{page.frontmatter.title}}`.
…to the templating engine
Instead of containing all page metadata, context only contains pages that are part of collections. Collections are defined in config and must point to a directory that is a direct descendant of the pagesDir, e.g. `/pages/posts` 👉 `posts`. Collections are based on the path (e.g. pages in `/pages/posts`). To make sure to only include collection pages and not collection indices (e.g. `/pages/posts/index.html`), we check if the page has a `published_date`. The hardcoding of the frontmatter date key is intentional: in a follow-up commit, we can automatically make the published_date a JavaScript Date, to avoid having to do this manually in a processContext script. Inspired by Cobalt.
Deploying brut with Cloudflare Pages
|
This is useful for testing sorting by date
This required another iteration through pages. Any better suggestion to solve this faster is welcome.
robinmetral
changed the title
Pass side-wide context to the templating engine
Pass collection context to mustache
Aug 11, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #26
This is a pretty big change. Essentially, it:
These should be enough to move a lot of logic out of custom build scripts, starting with the basic use case of iterating through a list of articles to render them on a page.