-
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
head, header and footer can be specified as a function #1255
Conversation
Why is it necessary to remove the strict normalization of the front matter? I don’t think we want to encourage users to put anything they want in the front matter; that will make it harder for us to introduce new options in the future without breaking projects. What is the use case for adding arbitrary things into the front matter? |
The idea is coming from metadata that I would like to both display in the page, and consume outside. For example, author (to create a byline), source (which I use in pangea to refer to the original notebook, when applicable), tags, date_published, og_image, thumbnail, etc. Some of these might go in the head (to inform opengraph tags), some in the indexation / listings (typically, the tags), yet others in the footer (e.g. tags with links to the tags pages. Maybe it's the wrong approach and we should reserve front matter for “official business”, but then we'd need another mechanism that would be more extensible in user land. Maybe it's just a "meta" key in front matter that is not normalized, and made available both for SSR and for client-side JS? Anyway I can dumb down this PR so that it only does the "head as a function" part and finally closes #56, and we continue the discussion on the extensibility separately. |
Yes, let’s separate these things. I’d definitely want the “user space” for the front matter to be isolated from Framework’s options, say by using a meta or data option. This also overlaps with the page loader concept #1216 which allows the entire page (not just the head, header, footer) to be dynamically generated. But I think it’s still likely reasonable to allow these options to be specified as functions in the config. |
rebased |
src/config.ts
Outdated
/** | ||
* A function that generates a page fragment such as head, header or footer. | ||
*/ | ||
type PageFragmentFunction = (title: string | null, data: FrontMatter, path: string) => string; |
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.
Would rather use named arguments here (({title, data, path})
), not positional ((title, data, path)
), so that it’s easier for us to add more arguments in the future without it becoming unwieldy.
Also this type is referenced by Config
and hence should be exported.
Co-authored-by: Mike Bostock <[email protected]>
Co-authored-by: Mike Bostock <[email protected]>
Looks like you’ll need to handle the case where the function returns null. (I think it should do that for consistency with the statically-supplied value.) |
showing "undefined" or "null" was not very pretty (but … informative!) :) |
I've tried defining a dynamic |
@dleeftink What version of framework are you using? |
@Fil an older one it seems (1.5.1), updated now tot 1.9.0 and no issues with the main footer: ()=>`test` |
Also, how about making the per-page overrides configurable to replace ( header: ({append = true}) => `<i>some subtitle</i>` Maybe overrides can even be configured to replace/append to specific metadata fields, for instance to append a date to a globally defined title or a metadata page description. Not sure what that interface would like tho as it involves creating per-field flags for potentially nested frontmatter items. EDIT: |
The current logic works the other way around: the function you define in |
head, header and footer can be specified as a function that receives the page’s meta data (path, title and normalized front matter), and returns an HTML fragment (string).
closes #56
Partially addresses #1036, but I'm not sure how we can (or if we should) expose the meta data more generally:
define("meta", …)
)?Partially addresses #1161.