Skip processing posts that can not be read (#7302)
Merge pull request 7302
This commit is contained in:
parent
7a1254563a
commit
ad7a5c0121
|
@ -34,19 +34,9 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_publishable(dir, magic_dir, matcher)
|
def read_publishable(dir, magic_dir, matcher)
|
||||||
read_content(dir, magic_dir, matcher).tap { |docs| docs.each(&:read) }
|
read_content(dir, magic_dir, matcher)
|
||||||
.select do |doc|
|
.tap { |docs| docs.each(&:read) }
|
||||||
if doc.content.valid_encoding?
|
.select { |doc| processable?(doc) }
|
||||||
site.publisher.publish?(doc).tap do |will_publish|
|
|
||||||
if !will_publish && site.publisher.hidden_in_the_future?(doc)
|
|
||||||
Jekyll.logger.debug "Skipping:", "#{doc.relative_path} has a future date"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Jekyll.logger.debug "Skipping:", "#{doc.relative_path} is not valid UTF-8"
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Read all the content files from <source>/<dir>/magic_dir
|
# Read all the content files from <source>/<dir>/magic_dir
|
||||||
|
@ -68,5 +58,27 @@ module Jekyll
|
||||||
:collection => @site.posts)
|
:collection => @site.posts)
|
||||||
end.reject(&:nil?)
|
end.reject(&:nil?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def processable?(doc)
|
||||||
|
if doc.content.nil?
|
||||||
|
Jekyll.logger.debug "Skipping:", "Content in #{doc.relative_path} is nil"
|
||||||
|
false
|
||||||
|
elsif !doc.content.valid_encoding?
|
||||||
|
Jekyll.logger.debug "Skipping:", "#{doc.relative_path} is not valid UTF-8"
|
||||||
|
false
|
||||||
|
else
|
||||||
|
publishable?(doc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def publishable?(doc)
|
||||||
|
site.publisher.publish?(doc).tap do |will_publish|
|
||||||
|
if !will_publish && site.publisher.hidden_in_the_future?(doc)
|
||||||
|
Jekyll.logger.debug "Skipping:", "#{doc.relative_path} has a future date"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
layout: default
|
||||||
|
title: This file extension is skipped
|
||||||
|
category: test_post_reader
|
||||||
|
---
|
||||||
|
|
||||||
|
`jekyll serve` used to crash if there's a post (document) with a wrong file extension.
|
||||||
|
This file is used in `./test/test_post_reader.rb` to verify that this doesn't happen anymore.
|
|
@ -0,0 +1,42 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "helper"
|
||||||
|
|
||||||
|
class TestPostReader < JekyllUnitTest
|
||||||
|
context "#read_publishable" do
|
||||||
|
setup do
|
||||||
|
@site = Site.new(site_configuration)
|
||||||
|
@post_reader = PostReader.new(@site)
|
||||||
|
@dir = ""
|
||||||
|
@magic_dir = "_posts"
|
||||||
|
@matcher = Document::DATE_FILENAME_MATCHER
|
||||||
|
end
|
||||||
|
|
||||||
|
should "skip unprocessable documents" do
|
||||||
|
all_file_names = all_documents.collect(&:basename)
|
||||||
|
processed_file_names = processed_documents.collect(&:basename)
|
||||||
|
|
||||||
|
actual_skipped_file_names = all_file_names - processed_file_names
|
||||||
|
|
||||||
|
expected_skipped_file_names = [
|
||||||
|
"2008-02-02-not-published.markdown",
|
||||||
|
"2008-02-03-wrong-extension.yml",
|
||||||
|
]
|
||||||
|
|
||||||
|
skipped_file_names_difference = expected_skipped_file_names - actual_skipped_file_names
|
||||||
|
|
||||||
|
assert expected_skipped_file_names.count.positive?,
|
||||||
|
"There should be at least one document expected to be skipped"
|
||||||
|
assert_empty skipped_file_names_difference,
|
||||||
|
"The skipped documents (expected/actual) should be congruent (= empty array)"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def all_documents
|
||||||
|
@post_reader.read_content(@dir, @magic_dir, @matcher)
|
||||||
|
end
|
||||||
|
|
||||||
|
def processed_documents
|
||||||
|
@post_reader.read_publishable(@dir, @magic_dir, @matcher)
|
||||||
|
end
|
||||||
|
end
|
|
@ -86,7 +86,7 @@ class TestSite < JekyllUnitTest
|
||||||
context "creating sites" do
|
context "creating sites" do
|
||||||
setup do
|
setup do
|
||||||
@site = Site.new(site_configuration)
|
@site = Site.new(site_configuration)
|
||||||
@num_invalid_posts = 4
|
@num_invalid_posts = 5
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
|
Loading…
Reference in New Issue