From d50656021f2ff9ea0f46bd1a58eb1b4f1cc83d1e Mon Sep 17 00:00:00 2001 From: rebornix Date: Fri, 27 Nov 2015 13:40:30 +0800 Subject: [PATCH 01/10] Fix #4188: Extract title from filename successfully when dateless. --- features/collections.feature | 19 +++++++++++++++++-- lib/jekyll/document.rb | 5 ++++- .../_thanksgiving/2015-11-26-thanksgiving.md | 3 +++ test/source/_thanksgiving/black-friday.md | 3 +++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/source/_thanksgiving/2015-11-26-thanksgiving.md create mode 100644 test/source/_thanksgiving/black-friday.md 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 2911c4aa..d4db403c 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. @@ -294,6 +294,9 @@ module Jekyll }) merge_data!({ "date" => date }) if data['date'].nil? || data['date'].to_i == site.time.to_i data['title'] ||= slug.split('-').select(&:capitalize).join(' ') + 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 }} From f8e86721481eff5f12910f0be800a1e36a790381 Mon Sep 17 00:00:00 2001 From: Jordon Bedwell Date: Sat, 28 Nov 2015 01:22:24 -0600 Subject: [PATCH 02/10] Fix #4191: Reduce Document#post_read complexity slightly. --- lib/jekyll/document.rb | 32 ++++++++++++++++++-------------- lib/jekyll/utils.rb | 8 ++++++-- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index d4db403c..51d0514e 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -286,24 +286,21 @@ 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 - }) - merge_data!({ "date" => date }) if data['date'].nil? || data['date'].to_i == site.time.to_i - data['title'] ||= slug.split('-').select(&:capitalize).join(' ') + if relative_path =~ DATE_FILENAME_MATCHER + cats, date, slug, ext = $1, $2, $3, $4 + merge_data!("date" => date) if !data['date'] || data['date'].to_i == site.time.to_i 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(' ') + cats, slug, ext = $1, $2, $3 end + + merge_data!("slug" => slug, "ext" => ext) + + # Try to ensure the user gets a title. + data["title"] ||= Utils.titleize_slug(slug) + 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. @@ -440,5 +437,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..6e0023de 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -10,8 +10,12 @@ module Jekyll SLUGIFY_DEFAULT_REGEXP = Regexp.new('[^[:alnum:]]+').freeze SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze - def strip_heredoc(str) - str.gsub(/^[ \t]{#{(str.scan(/^[ \t]*(?=\S)/).min || "").size}}/, "") + # 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. From 1ba23c32c69ad70721615e5b5cb82aef34606534 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 20 Jan 2016 11:46:18 -0800 Subject: [PATCH 03/10] add Utils.strip_heredoc --- lib/jekyll/utils.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb index 6e0023de..6dd2b117 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -10,6 +10,12 @@ 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) From 1298ba6908e9beaa30462ae0d6ba45e776c7e806 Mon Sep 17 00:00:00 2001 From: rebornix Date: Fri, 27 Nov 2015 13:40:30 +0800 Subject: [PATCH 04/10] Fix #4188: Extract title from filename successfully when dateless. --- features/collections.feature | 19 +++++++++++++++++-- lib/jekyll/document.rb | 5 ++++- .../_thanksgiving/2015-11-26-thanksgiving.md | 3 +++ test/source/_thanksgiving/black-friday.md | 3 +++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/source/_thanksgiving/2015-11-26-thanksgiving.md create mode 100644 test/source/_thanksgiving/black-friday.md 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 }} From 67f842546efa980146778c85fb613e6c9b53dcb4 Mon Sep 17 00:00:00 2001 From: Jordon Bedwell Date: Sat, 28 Nov 2015 01:22:24 -0600 Subject: [PATCH 05/10] Fix #4191: Reduce Document#post_read complexity slightly. --- lib/jekyll/document.rb | 34 +++++++++++++++++++--------------- lib/jekyll/utils.rb | 8 ++++++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index b8c162a5..c6f3cb87 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -289,26 +289,23 @@ 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 = $1, $2, $3, $4 + if !data['date'] || 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(' ') + elsif relative_path =~ DATELESS_FILENAME_MATCHER + _, slug, ext = $1, $2, $3 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_tags - - if generate_excerpt? - data['excerpt'] ||= Jekyll::Excerpt.new(self) - end + generate_excerpt end # Add superdirectories of the special_dir to categories. @@ -445,5 +442,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..6e0023de 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -10,8 +10,12 @@ module Jekyll SLUGIFY_DEFAULT_REGEXP = Regexp.new('[^[:alnum:]]+').freeze SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze - def strip_heredoc(str) - str.gsub(/^[ \t]{#{(str.scan(/^[ \t]*(?=\S)/).min || "").size}}/, "") + # 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. From 8204e479c38f2c0fafbf504b8929c74190ee145f Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 20 Jan 2016 11:46:18 -0800 Subject: [PATCH 06/10] add Utils.strip_heredoc --- lib/jekyll/utils.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb index 6e0023de..6dd2b117 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -10,6 +10,12 @@ 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) From ba1cfab73c785a4153bfda14c72c7f5ac4100428 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 22 Jan 2016 09:36:25 -0800 Subject: [PATCH 07/10] step_definitions: fixture collections should copy _thanksgiving --- features/step_definitions.rb | 1 + 1 file changed, 1 insertion(+) 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 # From 6c40c7f553fca8eddd5cc42f86b141d1245e2a89 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 22 Jan 2016 09:36:37 -0800 Subject: [PATCH 08/10] collections.feature: check for 0 exit status always --- features/collections.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/collections.feature b/features/collections.feature index 90715b57..ad17a896 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -168,7 +168,8 @@ Feature: Collections output: true """ When I run jekyll build - Then the _site directory should exist + Then I should get a zero exit status + And 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" From 5878acaaf1a0e0883364143abde32447b4f2f771 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 22 Jan 2016 09:36:55 -0800 Subject: [PATCH 09/10] Document#post_read: only overwrite slug & ext if they aren't set by YAML --- lib/jekyll/document.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index c6f3cb87..2840ba51 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -290,18 +290,19 @@ module Jekyll def post_read if relative_path =~ DATE_FILENAME_MATCHER - _, date, slug, ext = $1, $2, $3, $4 + 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 = $1, $2, $3 + slug, ext = $2, $3 end - merge_data!({"slug" => slug, "ext" => ext}, source: "filename") - # 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 From 2b8de5971725d4fb5404566f5d572cbe32ebf83a Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 22 Jan 2016 09:38:34 -0800 Subject: [PATCH 10/10] remove merge conflict --- lib/jekyll/document.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 94def29b..2840ba51 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -443,11 +443,7 @@ module Jekyll super end end -<<<<<<< HEAD -======= - ->>>>>>> origin/pull/cleanup-document__post_read private # :nodoc: def generate_excerpt if generate_excerpt?