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

Scope path glob #6268

Merged
merged 3 commits into from Oct 9, 2017

Conversation

Projects
None yet
6 participants
@alexey-pelykh
Contributor

alexey-pelykh commented Aug 4, 2017

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:

defaults:
  # Content
  -
    scope:
      path: "content/*.pdf"
    values:
      sitemap: false
  -
    scope:
      path: "content/*.html"
    values:
      sitemap: true

or

defaults:
  # Offers
  -
    scope:
      path: "offers/*/index.html"
    values:
      layout: offer
  -
    scope:
      path: "offers/*/thank-you.html"
    values:
      sitemap: false
@site = fixture_site({
"defaults" => [{
"scope" => {
"path" => "contacts/*.html",

This comment has been minimized.

@parkr

parkr Aug 4, 2017

Member

What happens if I have *.html here? Should it apply to about.html and contacts/index.html?

@parkr

parkr Aug 4, 2017

Member

What happens if I have *.html here? Should it apply to about.html and contacts/index.html?

This comment has been minimized.

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

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

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

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

This comment has been minimized.

@parkr

parkr Aug 4, 2017

Member

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.

@parkr

parkr Aug 4, 2017

Member

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.

This comment has been minimized.

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

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?

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

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?

This comment has been minimized.

@parkr

parkr Aug 4, 2017

Member

It should definitely be documented! If you wanted to apply to just root, would /*.html work?

@parkr

parkr Aug 4, 2017

Member

It should definitely be documented! If you wanted to apply to just root, would /*.html work?

This comment has been minimized.

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

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

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

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

This comment has been minimized.

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

Regarding the documentation - where should I write what?

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

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|

This comment has been minimized.

@parkr

parkr Aug 4, 2017

Member

We have some code in EntryFilter#glob_include? we might be able to use here.

@parkr

parkr Aug 4, 2017

Member

We have some code in EntryFilter#glob_include? we might be able to use here.

This comment has been minimized.

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

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?

@alexey-pelykh

alexey-pelykh Aug 4, 2017

Contributor

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 parkr self-assigned this Aug 4, 2017

@parkr parkr added accepted labels Aug 4, 2017

@alexey-pelykh

This comment has been minimized.

Show comment
Hide comment
@alexey-pelykh

alexey-pelykh Aug 16, 2017

Contributor

@parkr what's next?

Contributor

alexey-pelykh commented Aug 16, 2017

@parkr what's next?

@alexey-pelykh

This comment has been minimized.

Show comment
Hide comment
@alexey-pelykh

alexey-pelykh Sep 25, 2017

Contributor

@parkr rebased

Contributor

alexey-pelykh commented Sep 25, 2017

@parkr rebased

@DirtyF

This comment has been minimized.

Show comment
Hide comment
@DirtyF

DirtyF Sep 25, 2017

Member

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

Member

DirtyF commented Sep 25, 2017

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

@ashmaroli

This comment has been minimized.

Show comment
Hide comment
@ashmaroli

ashmaroli Sep 25, 2017

Member

If you can refactor it's great, if not just add the offended file in .rubocop.yml

Do not add the file to .rubocop.yml.
Instead refactor the two Pathname.new(sanitized_path).ascend { |path| [...] } into a private method..

That should appease Rubocop..
Also the last return isn't necessary.. Ruby always returns the last statement evaluated..

Member

ashmaroli commented Sep 25, 2017

If you can refactor it's great, if not just add the offended file in .rubocop.yml

Do not add the file to .rubocop.yml.
Instead refactor the two Pathname.new(sanitized_path).ascend { |path| [...] } into a private method..

That should appease Rubocop..
Also the last return isn't necessary.. Ruby always returns the last statement evaluated..

@alexey-pelykh

This comment has been minimized.

Show comment
Hide comment
@alexey-pelykh

alexey-pelykh Sep 25, 2017

Contributor

@DirtyF to which section should I add that example?
@ashmaroli hope it will work better now

Contributor

alexey-pelykh commented Sep 25, 2017

@DirtyF to which section should I add that example?
@ashmaroli hope it will work better now

path_is_subpath?(sanitized_path, rel_scope_path)
end
def path_is_subpath?(path, parent_path)

This comment has been minimized.

@ashmaroli

ashmaroli Sep 25, 2017

Member

do you want to expose this method as a public method? or would it rather be a private helper method?

@ashmaroli

ashmaroli Sep 25, 2017

Member

do you want to expose this method as a public method? or would it rather be a private helper method?

This comment has been minimized.

@alexey-pelykh

alexey-pelykh Sep 25, 2017

Contributor

@ashmaroli Isn't there a private scope starting right before applies?

@alexey-pelykh

alexey-pelykh Sep 25, 2017

Contributor

@ashmaroli Isn't there a private scope starting right before applies?

This comment has been minimized.

@ashmaroli

ashmaroli Sep 25, 2017

Member

right.. my bad.. ignore..

@ashmaroli

ashmaroli Sep 25, 2017

Member

right.. my bad.. ignore..

@alexey-pelykh

This comment has been minimized.

Show comment
Hide comment
@alexey-pelykh

alexey-pelykh Sep 26, 2017

Contributor

@DirtyF docs and example added

Contributor

alexey-pelykh commented Sep 26, 2017

@DirtyF docs and example added

@DirtyF DirtyF requested a review from jekyll/stability Sep 26, 2017

@parkr

parkr approved these changes Sep 28, 2017

❤️

@DirtyF DirtyF requested a review from Crunch09 Sep 28, 2017

@DirtyF DirtyF referenced this pull request Oct 9, 2017

Closed

excluding pdf files #194

@DirtyF

This comment has been minimized.

Show comment
Hide comment
@DirtyF

DirtyF Oct 9, 2017

Member

@jekyllbot: merge +minor

Member

DirtyF commented Oct 9, 2017

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit a78b518 into jekyll:master Oct 9, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@alexey-pelykh alexey-pelykh deleted the brainbeanapps:scope_path_glob branch Oct 9, 2017

@letrastudio

This comment has been minimized.

Show comment
Hide comment
@letrastudio

letrastudio Nov 8, 2017

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 commented Nov 8, 2017

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.

@DirtyF DirtyF added this to the v3.7.0 milestone Nov 8, 2017

@ashmaroli

This comment has been minimized.

Show comment
Hide comment
@ashmaroli

ashmaroli Nov 8, 2017

Member

@letrastudio this has already been merged to the master branch. It'll be included in the next release. If you want, you can use it right now by pointing your Gemfile to the master branch:

gem "jekyll", :git => "https://github.com/jekyll/jekyll.git"
Member

ashmaroli commented Nov 8, 2017

@letrastudio this has already been merged to the master branch. It'll be included in the next release. If you want, you can use it right now by pointing your Gemfile to the master branch:

gem "jekyll", :git => "https://github.com/jekyll/jekyll.git"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment