skip adding binary files as posts (#6344)

Merge pull request 6344
This commit is contained in:
Florian Thomas 2017-09-21 21:30:23 +01:00 committed by jekyllbot
parent 97d4437179
commit 47bcbfb654
2 changed files with 33 additions and 8 deletions

View File

@ -36,10 +36,15 @@ module Jekyll
def read_publishable(dir, magic_dir, matcher)
read_content(dir, magic_dir, matcher).tap { |docs| docs.each(&:read) }
.select do |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"
if doc.content.valid_encoding?
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 no valid UTF-8"
false
end
end
end

View File

@ -3,6 +3,22 @@
require "helper"
class TestSite < JekyllUnitTest
def with_image_as_post
tmp_image_path = File.join(source_dir, "_posts", "2017-09-01-jekyll-sticker.jpg")
FileUtils.cp File.join(Dir.pwd, "docs", "img", "jekyll-sticker.jpg"), tmp_image_path
yield
ensure
FileUtils.rm tmp_image_path
end
def read_posts
@site.posts.docs.concat(PostReader.new(@site).read_posts(""))
posts = Dir[source_dir("_posts", "**", "*")]
posts.delete_if do |post|
File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER)
end
end
context "configuring sites" do
should "have an array for plugins by default" do
site = Site.new default_configuration
@ -227,14 +243,18 @@ class TestSite < JekyllUnitTest
end
should "read posts" do
@site.posts.docs.concat(PostReader.new(@site).read_posts(""))
posts = Dir[source_dir("_posts", "**", "*")]
posts.delete_if do |post|
File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER)
end
posts = read_posts
assert_equal posts.size - @num_invalid_posts, @site.posts.size
end
should "skip posts with invalid encoding" do
with_image_as_post do
posts = read_posts
num_invalid_posts = @num_invalid_posts + 1
assert_equal posts.size - num_invalid_posts, @site.posts.size
end
end
should "read pages with YAML front matter" do
abs_path = File.expand_path("about.html", @site.source)
assert_equal true, Utils.has_yaml_header?(abs_path)