Skip to content

Commit

Permalink
Allow extensionless document in a strict site (#7950)
Browse files Browse the repository at this point in the history
Merge pull request 7950
  • Loading branch information
ashmaroli committed Apr 30, 2020
1 parent f451129 commit f69471c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
33 changes: 33 additions & 0 deletions features/collections.feature
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions lib/jekyll/document.rb
Expand Up @@ -498,13 +498,18 @@ 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
modify_date(date)
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!`)
Expand All @@ -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
Expand Down

0 comments on commit f69471c

Please sign in to comment.