From 1d14692e5d11842f3cfe8ffbb03efd9a7b1f1f99 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 6 Aug 2013 20:40:55 +0200 Subject: [PATCH 1/4] Implement URL conflict checking in `jekyll-doctor`. --- lib/jekyll/commands/doctor.rb | 41 +++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb index f11662d2..afdbdef9 100644 --- a/lib/jekyll/commands/doctor.rb +++ b/lib/jekyll/commands/doctor.rb @@ -6,23 +6,60 @@ module Jekyll site = Jekyll::Site.new(options) site.read - unless deprecated_relative_permalinks(site) + unless unhealthy(site) Jekyll.logger.info "Your test results", "are in. Everything looks fine." end end + def unhealthy(site) + [ + deprecated_relative_permalinks(site), + conflicting_urls(site) + ].any? + end + def deprecated_relative_permalinks(site) contains_deprecated_pages = false site.pages.each do |page| if page.uses_relative_permalinks Jekyll.logger.warn "Deprecation:", "'#{page.path}' uses relative" + " permalinks which will be deprecated in" + - " Jekyll v1.1 and beyond." + " Jekyll v1.2 and beyond." contains_deprecated_pages = true end end contains_deprecated_pages end + + def conflicting_urls(site) + conflicting_urls = false + urls = {} + urls = collect_urls(urls, site.pages, site.dest) + urls = collect_urls(urls, site.posts, site.dest) + #urls = collect_urls(urls, site.static_files) + urls.each do |url, paths| + if paths.size > 1 + conflicting_urls = true + Jekyll.logger.warn "Conflict:", "The URL '#{url}' is the destination" + + " for the following pages: #{paths.join(", ")}" + end + end + conflicting_urls + end + + private + + def collect_urls(urls, things, destination) + things.each do |thing| + dest = thing.destination(destination) + if urls[dest] + urls[dest] << thing.path + else + urls[dest] = [thing.path] + end + end + urls + end end end end From 318a379747dbb47644e48e053f8e29e8d6d6236a Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Thu, 8 Aug 2013 18:32:13 +0200 Subject: [PATCH 2/4] Nuke comment. --- lib/jekyll/commands/doctor.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb index afdbdef9..cf576fdd 100644 --- a/lib/jekyll/commands/doctor.rb +++ b/lib/jekyll/commands/doctor.rb @@ -36,7 +36,6 @@ module Jekyll urls = {} urls = collect_urls(urls, site.pages, site.dest) urls = collect_urls(urls, site.posts, site.dest) - #urls = collect_urls(urls, site.static_files) urls.each do |url, paths| if paths.size > 1 conflicting_urls = true From 7d26be510243abc8d0ce277f9700c1206116b6eb Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Thu, 8 Aug 2013 18:33:55 +0200 Subject: [PATCH 3/4] Call ruby's 'abort' if the site is unhealthy --- lib/jekyll/commands/doctor.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb index cf576fdd..8aca65c7 100644 --- a/lib/jekyll/commands/doctor.rb +++ b/lib/jekyll/commands/doctor.rb @@ -6,7 +6,9 @@ module Jekyll site = Jekyll::Site.new(options) site.read - unless unhealthy(site) + if unhealthy(site) + abort + else Jekyll.logger.info "Your test results", "are in. Everything looks fine." end end From 8b8fa4da4e96e184a88376cc9b8f76c37be17c13 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 17 Aug 2013 15:16:14 -0400 Subject: [PATCH 4/4] Use Doctor#healthy? and ensure _all_ items are checked before process quits. --- lib/jekyll/commands/doctor.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb index 8aca65c7..7ebab903 100644 --- a/lib/jekyll/commands/doctor.rb +++ b/lib/jekyll/commands/doctor.rb @@ -6,18 +6,18 @@ module Jekyll site = Jekyll::Site.new(options) site.read - if unhealthy(site) - abort - else + if healthy?(site) Jekyll.logger.info "Your test results", "are in. Everything looks fine." + else + abort end end - def unhealthy(site) + def healthy?(site) [ - deprecated_relative_permalinks(site), - conflicting_urls(site) - ].any? + !deprecated_relative_permalinks(site), + !conflicting_urls(site) + ].all? end def deprecated_relative_permalinks(site)