diff --git a/features/collections.feature b/features/collections.feature index 888bd1c2..90715b57 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -155,5 +155,20 @@ Feature: Collections """ 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" + 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 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" diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 8e0d3e86..b8c162a5 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -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. @@ -299,6 +299,9 @@ module Jekyll if data['date'].nil? || data['date'].to_i == site.time.to_i merge_data!({"date" => date}, source: "filename") 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 populate_categories populate_tags diff --git a/test/source/_thanksgiving/2015-11-26-thanksgiving.md b/test/source/_thanksgiving/2015-11-26-thanksgiving.md new file mode 100644 index 00000000..48d2dd58 --- /dev/null +++ b/test/source/_thanksgiving/2015-11-26-thanksgiving.md @@ -0,0 +1,3 @@ +--- +--- +Happy {{ page.title }} ! diff --git a/test/source/_thanksgiving/black-friday.md b/test/source/_thanksgiving/black-friday.md new file mode 100644 index 00000000..1d8ea1bb --- /dev/null +++ b/test/source/_thanksgiving/black-friday.md @@ -0,0 +1,3 @@ +--- +--- +{{ page.title }}