Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extensionless document in a strict site #7950

Merged
merged 3 commits into from Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions features/collections.feature
Expand Up @@ -610,3 +610,36 @@ Feature: Collections
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"

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 @@ -490,13 +490,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 @@ -508,6 +513,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