diff --git a/features/collections.feature b/features/collections.feature index 888bd1c2..ad17a896 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -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" diff --git a/features/step_definitions.rb b/features/step_definitions.rb index 2e47e369..f609076d 100644 --- a/features/step_definitions.rb +++ b/features/step_definitions.rb @@ -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 # diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 8e0d3e86..2840ba51 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. @@ -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 diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb index 9ffff548..6dd2b117 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -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. 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 }}