Change regex to sanitize and normalize filenames passed to LiquidRenderer (#6610)
Merge pull request 6610
This commit is contained in:
parent
1aae0bcc3a
commit
e1b64f9afd
|
@ -5,6 +5,11 @@ require_relative "liquid_renderer/table"
|
||||||
|
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class LiquidRenderer
|
class LiquidRenderer
|
||||||
|
extend Forwardable
|
||||||
|
|
||||||
|
def_delegator :@site, :in_source_dir, :source_dir
|
||||||
|
def_delegator :@site, :in_theme_dir, :theme_dir
|
||||||
|
|
||||||
def initialize(site)
|
def initialize(site)
|
||||||
@site = site
|
@site = site
|
||||||
Liquid::Template.error_mode = @site.config["liquid"]["error_mode"].to_sym
|
Liquid::Template.error_mode = @site.config["liquid"]["error_mode"].to_sym
|
||||||
|
@ -16,11 +21,13 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def file(filename)
|
def file(filename)
|
||||||
filename = @site.in_source_dir(filename).sub(
|
filename.match(filename_regex)
|
||||||
%r!\A#{Regexp.escape(@site.source)}/!,
|
filename =
|
||||||
""
|
if Regexp.last_match(1) == theme_dir("")
|
||||||
)
|
::File.join(Regexp.last_match(1).split("/")[-1], Regexp.last_match(2))
|
||||||
|
else
|
||||||
|
Regexp.last_match(2)
|
||||||
|
end
|
||||||
LiquidRenderer::File.new(self, filename).tap do
|
LiquidRenderer::File.new(self, filename).tap do
|
||||||
@stats[filename] ||= new_profile_hash
|
@stats[filename] ||= new_profile_hash
|
||||||
@stats[filename][:count] += 1
|
@stats[filename][:count] += 1
|
||||||
|
@ -44,6 +51,11 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def filename_regex
|
||||||
|
%r!\A(#{source_dir}/|#{theme_dir}/|\W*)(.*)!oi
|
||||||
|
end
|
||||||
|
|
||||||
def new_profile_hash
|
def new_profile_hash
|
||||||
Hash.new { |hash, key| hash[key] = 0 }
|
Hash.new { |hash, key| hash[key] = 0 }
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,5 +16,5 @@ ruby -e "contents = File.read('Gemfile'); File.write('Gemfile', contents.sub(/ge
|
||||||
echo "$0: installing default site dependencies"
|
echo "$0: installing default site dependencies"
|
||||||
BUNDLE_GEMFILE=Gemfile bundle install
|
BUNDLE_GEMFILE=Gemfile bundle install
|
||||||
echo "$0: building the default site"
|
echo "$0: building the default site"
|
||||||
BUNDLE_GEMFILE=Gemfile bundle exec jekyll build --verbose
|
BUNDLE_GEMFILE=Gemfile bundle exec jekyll build --verbose --profile
|
||||||
popd
|
popd
|
||||||
|
|
Loading…
Reference in New Issue