Fix #4188: Extract title from filename successfully when dateless.

This commit is contained in:
rebornix 2015-11-27 13:40:30 +08:00 committed by Parker Moore
parent c0e0159783
commit 1298ba6908
4 changed files with 27 additions and 3 deletions

View File

@ -155,5 +155,20 @@ Feature: Collections
""" """
When I run jekyll build When I run jekyll build
Then I should get a zero exit status Then I should get a zero exit status
And the _site directory should exist Then 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 "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 the _site directory should exist
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"

View File

@ -8,7 +8,7 @@ module Jekyll
attr_accessor :content, :output attr_accessor :content, :output
YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
DATELESS_FILENAME_MATCHER = /^(.*)(\.[^.]+)$/ DATELESS_FILENAME_MATCHER = /^(.+\/)*(.*)(\.[^.]+)$/
DATE_FILENAME_MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/ DATE_FILENAME_MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
# Create a new Document. # Create a new Document.
@ -299,6 +299,9 @@ module Jekyll
if data['date'].nil? || data['date'].to_i == site.time.to_i 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
m, cats, slug, ext = *relative_path.match(DATELESS_FILENAME_MATCHER)
data['title'] ||= slug.split('-').select {|w| w.capitalize! || w }.join(' ')
end end
populate_categories populate_categories
populate_tags populate_tags

View File

@ -0,0 +1,3 @@
---
---
Happy {{ page.title }} !

View File

@ -0,0 +1,3 @@
---
---
{{ page.title }}