-
Notifications
You must be signed in to change notification settings - Fork 133
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
Allow any frontmatter property to be overridden by site.json #784
Conversation
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.
Propose a merge commit message.
de10641
to
c1176c1
Compare
My bad, I can repush with a better message "Allow global override of frontmatter properties"? |
My apologies, maybe I wasn't clear, but when I mean a merge commit message, it is something like this. Basically it is a new format that we are adopting to explain the context of the change. The first paragraph is usually the current situation, the second paragraph explains why the current situation needs changes, and the third paragraph introduces our changes. If you are strapped for time, just tell me here and I will try to come up one for you. |
Sure, no problem
|
c1176c1
to
612a638
Compare
Rebased and updated |
Thanks for the commit message! I tidy up a bit to suit our convention better:
Rough description on changes made:
On a side note,
I don't think the original post expected it to be globally overridden, but rather that the individual |
yes, that's correct. The original expectation is to be able to override at src/glob level, not globally. |
So we want something like this?
|
Yes 👍 |
ec3811b
to
52fb236
Compare
Updated User can now specify a
|
Nice. Ensure that if a property is specified multiple times (e.g., via multiple globs) the latest value takes precedence, based on the order given in the site.json.
An alternative is to rename this as |
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.
Thanks for the pr @jamos-tay! I've left some comments regarding the overriding of values. Perhaps we could make it more explicit we are using default attributes if front matter doesn't exists. Additionally, the site.json
override could be a separate step that affects both branches. What do you think?
src/Page.js
Outdated
src: this.src, | ||
title: this.title || '', | ||
layout: LAYOUT_DEFAULT_NAME, | ||
...{ |
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.
Is there a reason why this is in an object?
Perhaps we could do
const defaultAttributes = {
src: this.src,
title: this.title || '',
layout: LAYOUT_DEFAULT_NAME,
}
this.frontMatter = {
...defaultAttributes
Additionally, this could collapse with the logic above? the title check and layout check seems redundant there.
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.
On second thought perhaps we could do something like
let front matter = { default }
if (specified front matter exists)
front matter = specified front matter
// handle overrides
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.
Hmm this is a bit tricky because the default src and title actually takes priority over the specified front matter, we only use the specified one if they are undefined. But we also can't overwrite specified front matter with default because overriding with ... seems to include undefineds:
a = { x: 5 }
b = { x: undefined }
{...a, ...b } // { x: undefined }
layout: LAYOUT_DEFAULT_NAME, | ||
}, | ||
...this.frontmatterOverride, | ||
...this.globalOverride, |
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.
Here value specified by site.json
, namely this.title
would be overriden by frontmatterOverride
and globalOverride
if they specified a title. Would this be a concern?
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.
Probably not, it was discussed here that it's easier to keep it consistent than specially handle it
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.
Ah i see, then line 515 and 517 should be done before 512? Otherwise it would override frontmatterOverride
and globalOverride
which is inconsistent when front matter is not specified.
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.
Sure, makes sense to move it down for consistency
Sure, makes sense. It's not too much trouble to swap the priority |
64f447f
to
5f94fdf
Compare
Sorry for the late update, updated and rebased |
docs/userGuide/siteConfiguration.md
Outdated
@@ -152,6 +159,10 @@ The following properties will apply to `index.md`: | |||
|
|||
**An array of external scripts to be referenced on all pages.** To reference an external script only on specific pages, `externalScripts` should be specified in `pages` instead. Scripts referenced will be run before the layout script. | |||
|
|||
#### **`globalOverride`** | |||
|
|||
**Globally overrides properties in the front matter of all pages.** Any property included in the global override will automatically be merged with the front matter of every single page, and override them if the property exists. Also overrides front matter properties specified in `pages`. |
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.
This documented behaviour is no longer true? frontMatter
now has a higher overriding priority than globalOverride
with the latest implementation.
Also update frontMatter
's description accordingly.
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [X] Enhancement to an existing feature
Fixes #647
What is the rationale for this request?
We want to be able to globally override all frontmatter properties in a page
What changes did you make? (Give an overview)
Allow any property in the frontmatter to be overriden by
globalOverride
if specified in the site.json,Proposed commit message: