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

Merged
merged 3 commits into from May 21, 2014

Conversation

Projects
None yet
5 participants
@rdumont
Contributor

rdumont commented May 11, 2014

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:

_data/categories/dairy.yaml     => name: Dairy Products
_data/categories/spices.yaml    => name: Spices

Will result in:

categories:
  dairy:
    name: Dairy Products
  spices:
    name: Spices
@penibelst

This comment has been minimized.

Show comment
Hide comment
@penibelst

penibelst May 12, 2014

Member

Great. Can you please add a note to the documentation in /site/docs/datafiles.md?

Member

penibelst commented May 12, 2014

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 }}"

This comment has been minimized.

@parkr

parkr May 12, 2014

Member

What if I have a file _data/categories.yml that contains the value dairy: foobar? How is that handled?

@parkr

parkr May 12, 2014

Member

What if I have a file _data/categories.yml that contains the value dairy: foobar? How is that handled?

This comment has been minimized.

@rdumont

rdumont May 12, 2014

Contributor

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.

@rdumont

rdumont May 12, 2014

Contributor

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.

This comment has been minimized.

@parkr

parkr May 12, 2014

Member

Ok. Can you please add a test for this?

@parkr

parkr May 12, 2014

Member

Ok. Can you please add a test for this?

This comment has been minimized.

@rdumont

rdumont May 12, 2014

Contributor

Done 😃

@rdumont

rdumont May 12, 2014

Contributor

Done 😃

@rdumont rdumont closed this May 12, 2014

@rdumont rdumont reopened this May 12, 2014

@rdumont

This comment has been minimized.

Show comment
Hide comment
@rdumont

rdumont May 12, 2014

Contributor

I'm sorry, I accidentally clicked the close button.

Contributor

rdumont commented May 12, 2014

I'm sorry, I accidentally clicked the close button.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr May 12, 2014

Member

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.

Member

parkr commented May 12, 2014

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.

@rdumont

This comment has been minimized.

Show comment
Hide comment
@rdumont

rdumont May 14, 2014

Contributor

@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.

Contributor

rdumont commented May 14, 2014

@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.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr May 15, 2014

Member

Sorry, I didn't get what you meant by sprinkling in subdirectories

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?

Member

parkr commented May 15, 2014

Sorry, I didn't get what you meant by sprinkling in subdirectories

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?

@parkr parkr merged commit 3c6377d into jekyll:master May 21, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

parkr added a commit that referenced this pull request May 21, 2014

@penibelst

This comment has been minimized.

Show comment
Hide comment
@penibelst

penibelst May 21, 2014

Member

Can’t wait to use it.

Member

penibelst commented May 21, 2014

Can’t wait to use it.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr May 21, 2014

Member

Jekyll 2.1 should be out early next week!

Member

parkr commented May 21, 2014

Jekyll 2.1 should be out early next week!

@rdumont

This comment has been minimized.

Show comment
Hide comment
@rdumont

rdumont May 21, 2014

Contributor

Great, thanks! I'll give some thought about the doc page too, so that we can improve it.

Contributor

rdumont commented May 21, 2014

Great, thanks! I'll give some thought about the doc page too, so that we can improve it.

@rdumont rdumont deleted the rdumont:data-subdirectories branch May 21, 2014

@fkostadinov

This comment has been minimized.

Show comment
Hide comment
@fkostadinov

fkostadinov Jul 7, 2014

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 {% for org in site.data.orgs %} and {{ org.name }} does not show anything. Interestingly, looping over all files in the subdirectory seems to recognize there are 2 files, because two entries are displayed. Is there anything missing in the examples (e.g. additional setup required in _config.yml, runtime arguments given to jekyll etc.)? Can someone please confirm the example works as given or provide an updated example? Thanks.

fkostadinov commented Jul 7, 2014

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 {% for org in site.data.orgs %} and {{ org.name }} does not show anything. Interestingly, looping over all files in the subdirectory seems to recognize there are 2 files, because two entries are displayed. Is there anything missing in the examples (e.g. additional setup required in _config.yml, runtime arguments given to jekyll etc.)? Can someone please confirm the example works as given or provide an updated example? Thanks.

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Jul 8, 2014

Member

@fkastadinov You're right! The example is wrong – great catch. The way to remedy it is to say instead of org, org[1]. When Liquid iterates over Hashes (which is what site.data.orgs is for this subdir), it gets an array that looks like this:

[
["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"}]}]
]

org[0] is the key (sanitized filename), and org[1] is the value (the file's data).

Member

parkr commented Jul 8, 2014

@fkastadinov You're right! The example is wrong – great catch. The way to remedy it is to say instead of org, org[1]. When Liquid iterates over Hashes (which is what site.data.orgs is for this subdir), it gets an array that looks like this:

[
["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"}]}]
]

org[0] is the key (sanitized filename), and org[1] is the value (the file's data).

@fkostadinov

This comment has been minimized.

Show comment
Hide comment
@fkostadinov

fkostadinov Jul 9, 2014

@parkr: Thanks, now everything works.

fkostadinov commented Jul 9, 2014

@parkr: Thanks, now everything works.

parkr added a commit that referenced this pull request Jul 9, 2014

@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Jul 9, 2014

Member

@fkostadinov Can you please confirm that the change made in e8e245e works?

Member

parkr commented Jul 9, 2014

@fkostadinov Can you please confirm that the change made in e8e245e works?

@fkostadinov

This comment has been minimized.

Show comment
Hide comment
@fkostadinov

fkostadinov Jul 9, 2014

@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.

fkostadinov commented Jul 9, 2014

@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.

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.