Skip to content
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

Global data files priority according to file extensions #794 #821

Merged
merged 2 commits into from
Jan 23, 2020

Conversation

gloryofrobots
Copy link
Contributor

This PR resolves #794 and also adds merging of global data from different files with the same base filename into one object

For example if we have files

//_data/data.js
module.exports = {
  key1: "js-val1"
}

// _data/data.json
{
   "key1": "json-val1",
   "key2": "json-val2"
}

resulting data objects will be merged according to extension priority so js will override json

{
  "key1":  "js-val1",
  "key2":  "json-val2"
}

Working on this PR I found that 11tydata.{json|js} files are not supported due to code in TemplateData.getObjectPathForDataFile
I do not know if it is a bug or a normal behavior. To clarify this I created #820

@zachleat
Copy link
Member

Please read #820 (comment)

@zachleat
Copy link
Member

As stated in #820 I have a few concerns that this will be a breaking change for folks? This might need to roll out in 1.0

@zachleat zachleat added the breaking-change This will have to be included with a major version as it breaks backwards compatibility. label Dec 20, 2019
@zachleat zachleat added this to the Next Major Version milestone Dec 20, 2019
@gloryofrobots
Copy link
Contributor Author

gloryofrobots commented Dec 21, 2019

Thanks for the feedback.
This PR doesn't change how TemplateData.getObjectPathForDataFile works. So _data/globalfile.11tydata.json will work as before.
Here I implemented the extension priority (so js will rank higher than json) and data merging according to this priority. Maybe, it will not break existing codebases because most of the projects, probably do not use the same filenames with different extensions for global data. In the current state, such data objects will override each other depending on the glob result order which is very unreliable in any case.

@zachleat
Copy link
Member

In the current state, such data objects will override each other depending on the glob result order which is very unreliable in any case.

Agree, yes. Makes good sense. I’ll remove the breaking change tag here.

@zachleat zachleat removed the breaking-change This will have to be included with a major version as it breaks backwards compatibility. label Dec 28, 2019
@zachleat zachleat removed this from the Next Major Version milestone Dec 28, 2019
@zachleat zachleat merged commit 7843929 into 11ty:master Jan 23, 2020
@zachleat
Copy link
Member

Merging, thanks!

@zachleat zachleat added this to the Next Minor Version milestone Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global data doesn’t have explicit rules about data overrides when data file roots are the same
2 participants