-
-
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
Propagate _data folder from theme #8815
Conversation
All files from _data folder within remote theme are accessible in consumer project. The behaviour is exactly the same as for overrides of _includes and _layouts. Data files with the same name in consumer project override data files within remote theme.
@mgerzabek Have you tried using the Consider the following object:
|
No, as I’d been only been aiming at making it work in junction with So, regarding your question @ashmaroli, I see the ambiguity. How to go about it? Thinking back to my use case I’d be fine to remove the recursive directory walking since it’s good enough to distribute data files within |
Please try using the plugins in tandem. # in _config.yml
plugins:
- jekyll-remote-theme
- jekyll-data
That is a good alternative I had not considered. The plugin I wrote is recursive within themes as well for parity with behavior for data files at source. I see your current implementation is recursive as well. Do note that if your primary need is for deploying with GitHub Pages, don't have high hopes. GHP is locked to Jekyll 3.9. This feature when ready will only go into Jekyll 4.x |
I understand and thank you for your clear words! This makes me rethink my initial considerations that where based on GHP via Otherwise I’d just leave this alone since, as I mentioned previously, I’m new to Ruby and the extra work means a lot of efforts beside my day to day job. (This BTW somehow makes me feel the original PR for @benbalter |
@mgerzabek This could sound a bit obtuse, but the chances of interested users seeing the comment above by Sep 30th is very slim. To increase the chances of visibility, you may want to consider utilizing platforms such as Jekyll Talk, Reddit or Twitter.
Technically, no. It wasn't the right location. However, since your primary need is to get this feature working on GHP and
My humble request would be to consider trying to migrate from GHP and use GitHub Actions to deploy your site. |
Right, so I‘ll edit the deadline to be 31st of October and do a post on Jekyll Talk Plz cast your votes until 31st of October 2021. Also feel free to share… |
+1 |
Ignore sub folders. Following the discussion in jekyll#8815 (comment) the theme reader now ignores subdirectories.
+1 |
I'm comfortable reading YAML/JSON from Have we decided how we want precedence to work? We should make sure our docs are clear for this, preferably with an example. 👍 |
One of my major use cases is a package of json files that goes along with my theme that is kept in _data/drinks. These get read and processed into pages by Jekyll-datapage-gen. If you don't want to scan all subfolders recursively for yml/json, you could allow explicit specification of folders to be scanned in _config.yml |
@parkr Please refer #8815 (comment) and let us know if the concern can be handled without impacting maintainability |
@ashmaroli I guess I’m a little confused, doesn’t that ambiguity already exist with the _data folder itself? Doesn’t exist with the use of your plugin Jekyll-data? What makes it any worse putting it into core? |
Yes, It does exist with
Having issues with a plugin is one thing. Bringing a known issue into Core is another. |
That makes sense. So if local data always overrides theme I don't see how it would cause confusion. I do think it makes sense to allow users to be explicit about which folders to include if they want. In my case, the theme would come with 500 or so files and a user may only want a handful of them. If they create a _data/drinks folder and place three new yml files inside, default behavior would be to include all the others as well, and some/many may not want that. Giving people a way to say "not this folder" or "only this folder" makes sense. Fortunately we already have that concept in Jekyll's _config.yml with "exclude:" |
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.
I think we should add this feature. I'd love to be able to reduce the differences between the ThemeDataReader and the Jekyll::DataReader classes so we can reuse the logic in the latter.
Tests are super thin for the DataReader class, so it would be great to add some more tests for that class using our fixture theme with some data files. 😄
Do you need help with any of this?
Use DataReader and recursively read contents from _data folder of theme if present and merge it with data from site _data folder. See jekyll#8815 (comment)
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 your patience on this one! I left fairly detailed comments with changes I'd propose. Let me know if you have any questions! Outstanding items:
- Write tests
- Site without a theme
- Site with a theme without _data
- Site with a theme with empty _data directory
- Site with a theme with data at root of _data, and in a subdirectory
- Write docs for our website (these can be done in a separate PR, e.g. https://jekyllrb.com/docs/themes/#understanding-gem-based-themes needs to be updated)
Thank you @parkr for the Jekyll/Ruby coaching. This was very insightful to me. I love the ambiguation at method level for initializing the reader. This is far advanced stuff I never would think about. Also the guarding of blocks is a rather new concept to me that combined with an unless seems very helpful on language level. Awesome! As a next step I’ll prepare the tests. After bringing it all to work I’ll open a separate pull request for updating the docs as suggested. |
@mgerzabek Like I have stated in the comment above, Since you're lost, I'll guide you towards finishing the Cucumber tests first.. You have already started with a new scenario in
|
Thank you @ashmaroli. Now I know how start the cucumber tests… and in the meantime I scanned through the introduction on cucumber on cucumber.io. If I understand correctly anything that I put into the scenario, like the data file in line 4 will be in the site. So with the Scenario: A theme with data
Given I have a configuration file with "theme" set to "test-theme"
And I have an _data directory
And I have an "_data/greetings.yml" file with content:
"""
foo: "Hello! I’m foo. And who are you?"
"""
And I have an "index.html" page that contains "{{ site.data.greetings.foo }}"
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should see "Hello! I’m foo. And who are you?" in "_site/index.html" Spoken the other way around when I change the key I changed the contents of Scenario: A theme without data
Given I have a configuration file with "theme" set to "test-theme"
And I have an "index.html" page that contains "{{ site.data.greetings.foo }}"
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should see "Hello! I’m bar. What’s up so far?" in "_site/index.html" Now both scenarios succeed. |
Okay, done. But counter intuitive to your request ist the last line in When I delete the file, then run the testsuite the file is created anyway. Not sure about that. |
Arrgh, too fast. Sorry @ashmaroli ! Where does this symlink point to? Do I have to recreate the symlink via terminal or is there a way I could use github to recreate it? I’m not sure how to proceed. |
@mgerzabek The commit a2b6aa2 and the associated PR has all the info to answer your questions. Give it a try. Don't waste your time though. I'll have a go at it before the final review. |
@ashmaroli as I don’t get the point, thank you for jumping in! |
The point being you were struggling and sometimes, it's easier just doing it instead of giving instructions that the other party can easily follow..
|
Thank you! Updated my local repo. So, is there anything left to do? How do we proceed from here? I’m curious how this works out… |
I'm not so pleased with the documentation. However, I'll defer sorting that and anything remaining to @parkr |
Well, @ashmaroli if you can tell me what should be improved I‘d jump in… not so pleased is kind of vague though. Anyways, @parkr said, the docs could be addressed in another PR as well… so why not proceed from here? |
You did tell us that you're not a native English speaker and hence the docs may not be up to expected level. It so happens that I'm not a native English speaker as well. So, my suggestions to improve the docs may be shot down by a consequent review. Let us wait for @parkr's inputs. If he doesn't get the time by Tuesday, I'll ping another maintainer. In the meantime, you could make the following edits (not mandatory, but highly recommended):
|
This looks great! I think further improvements could be made in a follow-up PR as needed as long as CI returns green. |
Thanks @mgerzabek |
Michael Gerzabek: Propagate _data folder from theme (#8815) Merge pull request 8815
Thanks @ashmaroli! |
Well done @mgerzabek and thanks @ashmaroli for the review! |
All files from _data folder within theme are accessible in consumer project. The behaviour is exactly the same as for overrides of _includes and _layouts. Data files with the same name in consumer project override data files within remote theme.
A similar PR was originally created for @benbalter jekyll-remote-theme which didn’t get the attention of the maintainers.
On 23rd of July @parkr said
So this my try on getting it into Jekyll upstream. And hopefully this way I can get what I wanted first, being able to access _data folder content in my remote themes :-)
This is a 🙋 feature or enhancement.
lib/jekyll/reader.rb:14:5: C: Metrics/AbcSize: Assignment Branch Condition size for read is too high. [<2, 26, 0> 26.08/23]
where I don’t really know how to go about that.Prior Art
jekyll-data
— plugin authored by @ashmaroli.