Skip to content
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

Reduce Pathname objects from front matter defaults #8067

Merged
merged 1 commit into from Mar 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 6 additions & 10 deletions lib/jekyll/frontmatter_defaults.rb
Expand Up @@ -103,15 +103,15 @@ def applies?(scope, path, type)
end

def applies_path?(scope, path)
return true if !scope.key?("path") || scope["path"].empty?
rel_scope_path = scope["path"]
return true if !rel_scope_path.is_a?(String) || rel_scope_path.empty?

sanitized_path = Pathname.new(sanitize_path(path))
rel_scope_path = Pathname.new(scope["path"])
sanitized_path = sanitize_path(path)

if scope["path"].to_s.include?("*")
if rel_scope_path.include?("*")
glob_scope(sanitized_path, rel_scope_path)
else
path_is_subpath?(sanitized_path, strip_collections_dir(scope["path"]))
path_is_subpath?(sanitized_path, strip_collections_dir(rel_scope_path))
end
end

Expand All @@ -134,11 +134,7 @@ def glob_cache(path)
end

def path_is_subpath?(path, parent_path)
path.ascend do |ascended_path|
return true if ascended_path.to_s == parent_path.to_s
end

false
path.start_with?(parent_path)
end

def strip_collections_dir(path)
Expand Down