Scope path glob - #6268
Conversation
| @site = fixture_site({ | ||
| "defaults" => [{ | ||
| "scope" => { | ||
| "path" => "contacts/*.html", |
There was a problem hiding this comment.
What happens if I have *.html here? Should it apply to about.html and contacts/index.html?
There was a problem hiding this comment.
Since we're using Dir.glob, according to docs, *.html will match only files on top directory, to match any HTML file, a **/*.html pattern should we used
There was a problem hiding this comment.
That's what would happen with the current code, yeah. I'm wondering if it makes sense to have *.html apply to all files in my entire source that end in .html. If I were using globs, that's what I would expect.
There was a problem hiding this comment.
Seems to me that EntryFilter#glob_include behaves in a similar way since File.fnmatch uses same rules of matching. Making *.html to match all files recursively will limit usability of the feature since if I want to set values only for root html files for whatever reason and not for any other - it will be impossible to achieve. Anyhow, this behaviour should be documented somewhere?
There was a problem hiding this comment.
It should definitely be documented! If you wanted to apply to just root, would /*.html work?
There was a problem hiding this comment.
Well, it would, though it would definitely take more custom logic that using Dir#glob and then there would be question why EntryFilter treats *.html differently
There was a problem hiding this comment.
Regarding the documentation - where should I write what?
| site_path = Pathname.new(@site.source) | ||
| rel_scope_path = Pathname.new(scope["path"]) | ||
| abs_scope_path = File.join(@site.source, rel_scope_path) | ||
| Dir.glob(abs_scope_path).each do |scope_path| |
There was a problem hiding this comment.
We have some code in EntryFilter#glob_include? we might be able to use here.
There was a problem hiding this comment.
Looked through that code, it relies on File#fnmatch? that uses the same rules as Dir#glob, though EntryFilter#glob_include? itself is not super-useful in this code, it would take more lines of code to reuse glob_include?
|
@parkr what's next? |
e86e53f to
dfe8017
Compare
|
@parkr rebased |
|
@alexey-pelykh That's great, could you add a usage example in our documentation? Note that CI is failing because of ABC/Metrics Cop. If you can refactor it's great, if not just add the offended file in |
Do not add the file to That should appease Rubocop.. |
|
@DirtyF to which section should I add that example? |
| path_is_subpath?(sanitized_path, rel_scope_path) | ||
| end | ||
|
|
||
| def path_is_subpath?(path, parent_path) |
There was a problem hiding this comment.
do you want to expose this method as a public method? or would it rather be a private helper method?
There was a problem hiding this comment.
@ashmaroli Isn't there a private scope starting right before applies?
|
@DirtyF docs and example added |
|
@jekyllbot: merge +minor |
|
Is it possible to attach this to a release milestone yet? Found it mentioned in the documentation (it was exactly what I was looking for!), sad to see it's unreleased. I can provide my specific usecase if it helps. |
|
@letrastudio this has already been merged to the gem "jekyll", :git => "https://github.com/jekyll/jekyll.git" |
Same as #5854
When this may be useful: when you have two different set of files (e.g. *.doc & *.pdf) in the same folder that requires different values used by Jekyll plugins or Jekyll itself.
Examples:
or