-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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 subdirectories in _data #2395
Conversation
Great. Can you please add a note to the documentation in /site/docs/datafiles.md? |
""" | ||
name: Dairy Products | ||
""" | ||
And I have an "index.html" page that contains "{{ site.data.categories.dairy.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.
What if I have a file _data/categories.yml
that contains the value dairy: foobar
? How is that handled?
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.
Because of how I list the entries in a directory (see line 213 of site.rb), directories will always override whatever is read from a file with the same name.
But this is due to a small detail in implementation. I think the behavior for such case should be considered unpredictable and people should be discouraged to name files the same as sub-directories. Just the same as they shouldn't have a .json
and a .yaml
with the same 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.
Ok. Can you please add a test for this?
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.
Done 😃
I'm sorry, I accidentally clicked the close button. |
Thanks for adding the docs. Can you please sprinkle in subdirectories in examples above the one you gave so it's more prominent? The entire Data Files doc page may require reworking. |
@parkr Sorry, I didn't get what you meant by sprinkling in subdirectories. But yeah, I agree that with this change the entire Data Files doc page would greatly benefit from some rework. |
I just meant showing subdirectories and flat files shown side-by-side in the other examples on the page. :) @benbalter Do you have any major thoughts on this? |
Can’t wait to use it. |
Jekyll 2.1 should be out early next week! |
Great, thanks! I'll give some thought about the doc page too, so that we can improve it. |
I fail to run the given example for subdirectories. I am running Jekyll 2.1.0 on Windows 7 with the exact setup given here: http://jekyllrb.com/docs/datafiles/. Whereas the first example with a single members.yml works perfectly fine, the second example with multiple files in a subdirectory does not. Contents read out with |
@fkastadinov You're right! The example is wrong – great catch. The way to remedy it is to say instead of [
["doeorg", {"username"=>"doeorg", "name"=>"Doe Org", "members"=>[{"name"=>"John Doe", "github"=>"jdoe"}]}],
["jekyll", {"username"=>"jekyll", "name"=>"Jekyll", "members"=>[{"name"=>"Tom Preston-Werner", "github"=>"mojombo"}, {"name"=>"Parker Moore", "github"=>"parkr"}]}]
]
|
@parkr: Thanks, now everything works. |
…_data. Addresses @fkostadinov's comment in #2395: #2395 (comment)
@fkostadinov Can you please confirm that the change made in e8e245e works? |
@parkr: Yes, I tried the updated example, and it works! Perhaps you could also mention quickly that in the subdirectory example files are read out as key/value pairs and that org_hash[0] contains the filename (without ending) and org[1] the file's contents. This would help clarify things for an inexperienced user. |
Fixes #2082 - Support subdirectories in _data.
Subdirectories in the
_data
folder will also be scanned for.yaml
,.yml
and.json
files, recursively. For more details, see the added Cucumber scenario and the examples below:Using the following files:
Will result in: