Merge pull request #4195 from jekyll/pull/cleanup-document__post_read
Merge pull request 4195
This commit is contained in:
commit
ccb382679a
|
@ -155,5 +155,21 @@ Feature: Collections
|
|||
"""
|
||||
When I run jekyll build
|
||||
Then I should get a zero exit status
|
||||
Then the _site directory should exist
|
||||
And I should see "Collections: Jekyll.configuration, Jekyll.escape, Jekyll.sanitized_path, Site#generate, Initialize, Site#generate, YAML with Dots," in "_site/index.html"
|
||||
|
||||
Scenario: Rendered collection with date/dateless filename
|
||||
Given I have an "index.html" page that contains "Collections: {% for method in site.thanksgiving %}{{ method.title }} {% endfor %}"
|
||||
And I have fixture collections
|
||||
And I have a "_config.yml" file with content:
|
||||
"""
|
||||
collections:
|
||||
thanksgiving:
|
||||
output: true
|
||||
"""
|
||||
When I run jekyll build
|
||||
Then I should get a zero exit status
|
||||
And the _site directory should exist
|
||||
And I should see "Collections: Jekyll.configuration, Jekyll.escape, Jekyll.sanitized_path, Site#generate, , Site#generate," in "_site/index.html"
|
||||
And I should see "Thanksgiving Black Friday" in "_site/index.html"
|
||||
And I should see "Happy Thanksgiving" in "_site/thanksgiving/2015-11-26-thanksgiving.html"
|
||||
And I should see "Black Friday" in "_site/thanksgiving/black-friday.html"
|
||||
|
|
|
@ -125,6 +125,7 @@ end
|
|||
|
||||
Given %r{^I have fixture collections$} do
|
||||
FileUtils.cp_r Paths.source_dir.join("test", "source", "_methods"), source_dir
|
||||
FileUtils.cp_r Paths.source_dir.join("test", "source", "_thanksgiving"), source_dir
|
||||
end
|
||||
|
||||
#
|
||||
|
|
|
@ -8,7 +8,7 @@ module Jekyll
|
|||
attr_accessor :content, :output
|
||||
|
||||
YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
||||
DATELESS_FILENAME_MATCHER = /^(.*)(\.[^.]+)$/
|
||||
DATELESS_FILENAME_MATCHER = /^(.+\/)*(.*)(\.[^.]+)$/
|
||||
DATE_FILENAME_MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
|
||||
|
||||
# Create a new Document.
|
||||
|
@ -289,23 +289,24 @@ module Jekyll
|
|||
end
|
||||
|
||||
def post_read
|
||||
if DATE_FILENAME_MATCHER =~ relative_path
|
||||
_, _, date, slug, ext = *relative_path.match(DATE_FILENAME_MATCHER)
|
||||
merge_data!({
|
||||
"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
|
||||
if relative_path =~ DATE_FILENAME_MATCHER
|
||||
date, slug, ext = $2, $3, $4
|
||||
if !data['date'] || data['date'].to_i == site.time.to_i
|
||||
merge_data!({"date" => date}, source: "filename")
|
||||
end
|
||||
elsif relative_path =~ DATELESS_FILENAME_MATCHER
|
||||
slug, ext = $2, $3
|
||||
end
|
||||
|
||||
# Try to ensure the user gets a title.
|
||||
data["title"] ||= Utils.titleize_slug(slug)
|
||||
# Only overwrite slug & ext if they aren't specified.
|
||||
data['slug'] ||= slug
|
||||
data['ext'] ||= ext
|
||||
|
||||
populate_categories
|
||||
populate_tags
|
||||
|
||||
if generate_excerpt?
|
||||
data['excerpt'] ||= Jekyll::Excerpt.new(self)
|
||||
end
|
||||
generate_excerpt
|
||||
end
|
||||
|
||||
# Add superdirectories of the special_dir to categories.
|
||||
|
@ -442,5 +443,12 @@ module Jekyll
|
|||
super
|
||||
end
|
||||
end
|
||||
|
||||
private # :nodoc:
|
||||
def generate_excerpt
|
||||
if generate_excerpt?
|
||||
data["excerpt"] ||= Jekyll::Excerpt.new(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,10 +10,20 @@ module Jekyll
|
|||
SLUGIFY_DEFAULT_REGEXP = Regexp.new('[^[:alnum:]]+').freeze
|
||||
SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
|
||||
|
||||
# Takes an indented string and removes the preceding spaces on each line
|
||||
|
||||
def strip_heredoc(str)
|
||||
str.gsub(/^[ \t]{#{(str.scan(/^[ \t]*(?=\S)/).min || "").size}}/, "")
|
||||
end
|
||||
|
||||
# Takes a slug and turns it into a simple title.
|
||||
|
||||
def titleize_slug(slug)
|
||||
slug.split("-").map! do |val|
|
||||
val.capitalize!
|
||||
end.join(" ")
|
||||
end
|
||||
|
||||
# Non-destructive version of deep_merge_hashes! See that method.
|
||||
#
|
||||
# Returns the merged hashes.
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
---
|
||||
Happy {{ page.title }} !
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
---
|
||||
{{ page.title }}
|
Loading…
Reference in New Issue