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
Refactor collections_dir feature for consistency #6685
Conversation
As a note, what I tripped over initially was that I assumed that a collections directory would be special directory (similar to collections_dir: _collections and a directory layout similar to
everything would be neatly arranged, and work fine. Note:
Just felt like throwing this in, as an FYI. |
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.
👍 Looks good, just some small things. Can we close #6679 as this supersedes that one?
features/collections_dir.feature
Outdated
Then I should get a zero exit status | ||
And the _site directory should exist | ||
And the "_site/puppies/rover.html" file should exist | ||
And the "_site/post-at-root.html" file should not exist |
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 understand it doesn't exist anyway but shouldn't that be _site/2009/03/27/post-at-root.html
?
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.
yes.. it should.. we ought to be checking for the expected outcomes.. 👍
features/collections_dir.feature
Outdated
And the "_site/puppies/rover-in-gathering.html" file should exist | ||
And the "_site/2009/03/27/post-in-gathering.html" file should exist | ||
And the "_site/2009/03/27/draft-in-gathering.html" file should exist | ||
And the "_site/gathering/2009/03/27/draft-in-gathering.html" file should not exist |
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.
A couple of lines below we check that the _site/gathering
directory doesn't exist, so no need to check for a file in a non-existing directory i think.
Given(%r!^I have the following documents? under the "(.*)" collection within the "(.*)" directory:$!) do |label, dir, table| | ||
table.hashes.each do |input_hash| | ||
title = slug(input_hash["title"]) | ||
path = File.join(dir, "_#{label}", "#{title}.md") |
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.
Any reason why you chose .md
for documents but .markdown
for the post / drafts step above?
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.
only because that's how our default site gets created from jekyll new
.. and I think, an existing step also has something similar set up.. not sure..
lib/jekyll/reader.rb
Outdated
# outside that directory. | ||
def not_within_configured_directory?(dir) | ||
collections_dir = site.config["collections_dir"] | ||
!collections_dir.empty? && !dir.start_with?("/#{collections_dir}") |
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 do you think of renaming this method to within_configured_directory?
and then just checking with unless
or if !
?
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.
it can be done.. I kept it negative so that human can readily parse two negative expressions easily in comparison to one negative and the other positive..
def within_configured_directory?(dir)
collections_dir = site.config["collections_dir"]
!collections_dir.empty? && dir.start_with?("/#{collections_dir}")
end
@localheinz I understand your suggestion completely.
|
a3f2a9f
to
39d0bad
Compare
I'm totally fine with |
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 adding those tests !
Minor concerns:
-
Even if we document this on the website or in the default
_config.yml
generated byjekyll new
, we should warn people that if acollection_dir
is defined they should move_posts
and_drafts
into_collection_dir
. Tests only check for a zero exit code, but it should trigger a warning in those use cases. This could be tackled in a new PR. -
Out of curiosity, why do we add a date to the collection documents here?
📦 Happy to release a 3.7.1 patch once the team is onboard with this 😄
Its not required at all, but existing scenarios had them, so I included them here as well.. will make it easier if future developers need to test for some other date-related parameter.. |
Then I should get a zero exit status | ||
And the _site directory should exist | ||
And the "_site/puppies/rover.html" file should exist | ||
And the "_site/2009/03/27/post-at-root.html" file should not exist |
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.
Woof, this is going to screw people up. We can't enforce that the _posts
directory is in the collections_dir
until 4.0, if we even want to.
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.
its not.. we just released this feature in 3.7.0
.. The sooner we ship this patch, the lesser no.of users gonna have issues..
Then I should get a zero exit status | ||
And the _site directory should exist | ||
And the "_site/puppies/rover.html" file should exist | ||
And the "_site/2009/03/27/draft-at-root.html" file should not exist |
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.
_drafts
can't be enforced to be in collections_dir
until 4.0 either.
@relative_directory ||= Pathname.new(directory).relative_path_from( | ||
Pathname.new(site.source) | ||
).to_s | ||
@relative_directory ||= "_#{label}" |
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 should be relative to the site source, so if source is .
then it should be collections_dir/_label
.
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.
Things that're going to break if @relative_directory ||= collections_dir/_label
:
Lines 32 to 36 in f77d704
if draft? | |
categories_from_path("_drafts") | |
else | |
categories_from_path(collection.relative_directory) | |
end |
Lines 76 to 79 in f77d704
def draft? | |
data["draft"] ||= relative_path.index(collection.relative_directory).nil? && | |
collection.label == "posts" | |
end |
Lines 121 to 124 in f77d704
def cleaned_relative_path | |
@cleaned_relative_path ||= | |
relative_path[0..-extname.length - 1].sub(collection.relative_directory, "") | |
end |
lib/jekyll/document.rb
Outdated
@@ -83,7 +83,7 @@ def draft? | |||
# Returns a String path which represents the relative path | |||
# from the site source to this document | |||
def relative_path | |||
@relative_path ||= Pathutil.new(path).relative_path_from(site.source).to_s | |||
@relative_path ||= Pathutil.new(path).relative_path_from(focal_point).to_s |
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.
Why can't this be the site.source? Are you thinking the collections_dir
needs to disappear in the output? Hm. Maybe relative_path_from(collection.path)
?
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.
collection
does not have an instance method :path
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.
Any reason it can't have that method? I don't like the focal_point
method – seems like it's capturing some logic that should be handled somewhere else, like path
.
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.
Any reason...?
I did not want to introduce a new public_method
in a patch-release..
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.
Well now that we have introduce a potential breaking change in a minor version, we should be above that kind of consideration here. The more collections_dir
behavior is well thought, the better.
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.
@parkr Your call.. should I introduce a new public_method in a patch-release..?
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 adding Collection#path to fix this bug is a fine solution for a patch release. SemVer makes no assumptions about methods being added, as far as I can tell. Our SemVer is guided by new features (minor bump) and breaking changes (major bump).
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 would call "enhancing" Collections
class with a new public_method
as a feature.. just like removing an existing public_method
is considered a breaking change..
That said, this is not the place for debating SemVer.. your comment above is clear enough an answer for how to proceed..
Will push a commit soon..
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.
Small change of plans.. Instead of having Collection#path
for each collection in a Site, I decided to compute the path once via Site#collections_path
Static files within a collection inside a custom collections_dir needs to output to the same path as when the collection is at the root of the source directory.
bfe2a2c
to
2af6834
Compare
@jekyllbot: merge +bug |
I believe this removes bugs with the recently released
collection_dir
feature reported via jekyll/jekyll-feed#202 and confirmed via #6679Basically with this patch,
collections_dir
setting is not customized.collections_dir
setting is customized, Jekyll looks for all collections within that directory only:collections_dir
my_collections
, then the relative_path for./my_collections/_puppies/rover.md
is simply_puppies/rover.md
collection_dir