Merge branch 'akoeplinger-doctor-permalink-same-case-warning'

* akoeplinger-doctor-permalink-same-case-warning:
  Added tests for new jekyll doctor warning
  Incorporate code review feedback
  Incorporate code review feedback
  Add a Jekyll doctor warning for URLs that only differ by case
This commit is contained in:
Parker Moore 2015-12-13 12:26:07 -08:00
commit fdcd761313
5 changed files with 77 additions and 1 deletions

View File

@ -32,7 +32,8 @@ module Jekyll
[
fsnotify_buggy?(site),
!deprecated_relative_permalinks(site),
!conflicting_urls(site)
!conflicting_urls(site),
!urls_only_differ_by_case(site)
].all?
end
@ -76,6 +77,20 @@ module Jekyll
true
end
def urls_only_differ_by_case(site)
urls_only_differ_by_case = false
urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
urls.each do |case_insensitive_url, real_urls|
if real_urls.uniq.size > 1
urls_only_differ_by_case = true
Jekyll.logger.warn "Warning:", "The following URLs only differ" +
" by case. On a case-insensitive file system one of the URLs" +
" will be overwritten by the other: #{real_urls.join(", ")}"
end
end
urls_only_differ_by_case
end
private
def collect_urls(urls, things, destination)
things.each do |thing|
@ -89,6 +104,13 @@ module Jekyll
urls
end
def case_insensitive_urls(things, destination)
things.inject(Hash.new) do |memo, thing|
dest = thing.destination(destination)
(memo[dest.downcase] ||= []) << dest
memo
end
end
end
end

View File

@ -0,0 +1,6 @@
---
title: About
permalink: /about/
---
About the site

View File

@ -0,0 +1,6 @@
---
title: About
permalink: /About/
---
About the site

View File

@ -0,0 +1,6 @@
---
title: About
permalink: /about/
---
About the site

View File

@ -0,0 +1,36 @@
require 'helper'
require 'jekyll/commands/doctor'
class TestDoctorCommand < Test::Unit::TestCase
context 'urls only differ by case' do
setup do
clear_dest
end
should 'return success on a valid site/page' do
@site = Site.new(Jekyll.configuration({
"source" => File.join(source_dir, '/_urls_differ_by_case_valid'),
"destination" => dest_dir
}))
@site.process
output = capture_stderr do
ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site)
assert_equal false, ret
end
assert_equal "", output
end
should 'return warning for pages only differing by case' do
@site = Site.new(Jekyll.configuration({
"source" => File.join(source_dir, '/_urls_differ_by_case_invalid'),
"destination" => dest_dir
}))
@site.process
output = capture_stderr do
ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site)
assert_equal true, ret
end
assert_equal "\e[33m Warning: The following URLs only differ by case. On a case-insensitive file system one of the URLs will be overwritten by the other: #{dest_dir}/about/index.html, #{dest_dir}/About/index.html\e[0m\n", output
end
end
end