From 1d14692e5d11842f3cfe8ffbb03efd9a7b1f1f99 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 6 Aug 2013 20:40:55 +0200 Subject: [PATCH] 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