diff --git a/features/collections.feature b/features/collections.feature index 5924e7e6bc6..1edda78e81d 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -624,3 +624,36 @@ Feature: Collections Then I should get a zero exit status And the _site directory should exist And I should see "I have no front matter." in "_site/methods/extensionless_static_file" + + Scenario: Rendered collection with an extensionless document + Given I have fixture collections + And I have a "_config.yml" file with content: + """ + collections: + methods: + 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 "I have no file extension but I should still be a part of the collection." in "_site/methods/collection/entries" + + Scenario: Rendered collection with an extensionless document in a strict site + Given I have fixture collections + And I have a _posts directory + And I have an "_posts/2019-12-26-extensioned.md" file that contains "Hello!" + And I have an "_posts/2019-12-26-extensionless" file that contains "Aloha!" + And I have an "index.md" page that contains "{{ site.posts | map: 'title' }}" + And I have a "_config.yml" file with content: + """ + strict_front_matter: true + collections: + methods: + 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 "I have no file extension but I should still be a part of the collection." in "_site/methods/collection/entries" + And I should see "Extensioned" in "_site/index.html" + But I should not see "Extensionless" in "_site/index.html" diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index c918996f788..80f7aab4e2b 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -498,6 +498,7 @@ def handle_read_error(error) end end + # rubocop:disable Metrics/AbcSize def populate_title if relative_path =~ DATE_FILENAME_MATCHER date, slug, ext = Regexp.last_match.captures @@ -505,6 +506,10 @@ def populate_title elsif relative_path =~ DATELESS_FILENAME_MATCHER slug, ext = Regexp.last_match.captures end + # `slug` will be nil for documents without an extension since the regex patterns + # above tests for an extension as well. + # In such cases, assign `basename_without_ext` as the slug. + slug ||= basename_without_ext # slugs shouldn't end with a period # `String#gsub!` removes all trailing periods (in comparison to `String#chomp!`) @@ -516,6 +521,7 @@ def populate_title data["slug"] ||= slug data["ext"] ||= ext end + # rubocop:enable Metrics/AbcSize def modify_date(date) if !data["date"] || data["date"].to_i == site.time.to_i