Implement URL conflict checking in `jekyll-doctor`.

This commit is contained in:
Parker Moore 2013-08-06 20:40:55 +02:00
parent a7356f065d
commit 1d14692e5d
1 changed files with 39 additions and 2 deletions

View File

@ -6,23 +6,60 @@ module Jekyll
site = Jekyll::Site.new(options) site = Jekyll::Site.new(options)
site.read site.read
unless deprecated_relative_permalinks(site) unless unhealthy(site)
Jekyll.logger.info "Your test results", "are in. Everything looks fine." Jekyll.logger.info "Your test results", "are in. Everything looks fine."
end end
end end
def unhealthy(site)
[
deprecated_relative_permalinks(site),
conflicting_urls(site)
].any?
end
def deprecated_relative_permalinks(site) def deprecated_relative_permalinks(site)
contains_deprecated_pages = false contains_deprecated_pages = false
site.pages.each do |page| site.pages.each do |page|
if page.uses_relative_permalinks if page.uses_relative_permalinks
Jekyll.logger.warn "Deprecation:", "'#{page.path}' uses relative" + Jekyll.logger.warn "Deprecation:", "'#{page.path}' uses relative" +
" permalinks which will be deprecated in" + " permalinks which will be deprecated in" +
" Jekyll v1.1 and beyond." " Jekyll v1.2 and beyond."
contains_deprecated_pages = true contains_deprecated_pages = true
end end
end end
contains_deprecated_pages contains_deprecated_pages
end 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 end
end end