Fix #4191: Reduce Document#post_read complexity slightly.
This commit is contained in:
parent
1298ba6908
commit
67f842546e
|
@ -289,26 +289,23 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_read
|
def post_read
|
||||||
if DATE_FILENAME_MATCHER =~ relative_path
|
if relative_path =~ DATE_FILENAME_MATCHER
|
||||||
_, _, date, slug, ext = *relative_path.match(DATE_FILENAME_MATCHER)
|
_, date, slug, ext = $1, $2, $3, $4
|
||||||
merge_data!({
|
if !data['date'] || data['date'].to_i == site.time.to_i
|
||||||
"slug" => slug,
|
|
||||||
"ext" => ext
|
|
||||||
}, source: "filename")
|
|
||||||
data['title'] ||= slug.split('-').select(&:capitalize).join(' ')
|
|
||||||
if data['date'].nil? || data['date'].to_i == site.time.to_i
|
|
||||||
merge_data!({"date" => date}, source: "filename")
|
merge_data!({"date" => date}, source: "filename")
|
||||||
end
|
end
|
||||||
elsif DATELESS_FILENAME_MATCHER =~ relative_path
|
elsif relative_path =~ DATELESS_FILENAME_MATCHER
|
||||||
m, cats, slug, ext = *relative_path.match(DATELESS_FILENAME_MATCHER)
|
_, slug, ext = $1, $2, $3
|
||||||
data['title'] ||= slug.split('-').select {|w| w.capitalize! || w }.join(' ')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
merge_data!({"slug" => slug, "ext" => ext}, source: "filename")
|
||||||
|
|
||||||
|
# Try to ensure the user gets a title.
|
||||||
|
data["title"] ||= Utils.titleize_slug(slug)
|
||||||
|
|
||||||
populate_categories
|
populate_categories
|
||||||
populate_tags
|
populate_tags
|
||||||
|
generate_excerpt
|
||||||
if generate_excerpt?
|
|
||||||
data['excerpt'] ||= Jekyll::Excerpt.new(self)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add superdirectories of the special_dir to categories.
|
# Add superdirectories of the special_dir to categories.
|
||||||
|
@ -445,5 +442,12 @@ module Jekyll
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private # :nodoc:
|
||||||
|
def generate_excerpt
|
||||||
|
if generate_excerpt?
|
||||||
|
data["excerpt"] ||= Jekyll::Excerpt.new(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,8 +10,12 @@ module Jekyll
|
||||||
SLUGIFY_DEFAULT_REGEXP = Regexp.new('[^[:alnum:]]+').freeze
|
SLUGIFY_DEFAULT_REGEXP = Regexp.new('[^[:alnum:]]+').freeze
|
||||||
SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
|
SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
|
||||||
|
|
||||||
def strip_heredoc(str)
|
# Takes a slug and turns it into a simple title.
|
||||||
str.gsub(/^[ \t]{#{(str.scan(/^[ \t]*(?=\S)/).min || "").size}}/, "")
|
|
||||||
|
def titleize_slug(slug)
|
||||||
|
slug.split("-").map! do |val|
|
||||||
|
val.capitalize!
|
||||||
|
end.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Non-destructive version of deep_merge_hashes! See that method.
|
# Non-destructive version of deep_merge_hashes! See that method.
|
||||||
|
|
Loading…
Reference in New Issue