From 8875bdf900d8b4d383499b4f5ebd833ac8fd92b2 Mon Sep 17 00:00:00 2001 From: Pat Hawks Date: Thu, 12 Jan 2017 14:09:50 -0600 Subject: [PATCH] Add URL checks to Doctor --- lib/jekyll/commands/doctor.rb | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb index c7f387df7bb..0db12febab2 100644 --- a/lib/jekyll/commands/doctor.rb +++ b/lib/jekyll/commands/doctor.rb @@ -1,3 +1,5 @@ +require "addressable/uri" + module Jekyll module Commands class Doctor < Command @@ -35,7 +37,8 @@ def healthy?(site) fsnotify_buggy?(site), !deprecated_relative_permalinks(site), !conflicting_urls(site), - !urls_only_differ_by_case(site) + !urls_only_differ_by_case(site), + proper_site_url?(site) ].all? end @@ -91,6 +94,13 @@ def urls_only_differ_by_case(site) urls_only_differ_by_case end + def proper_site_url?(site) + url = site.config["url"] + url_exists?(url) && + url_valid?(url) && + url_absolute(url) + end + private def collect_urls(urls, things, destination) things.each do |thing| @@ -110,6 +120,27 @@ def case_insensitive_urls(things, destination) (memo[dest.downcase] ||= []) << dest end end + + def url_exists?(url) + return true unless url.nil? || url.empty? + Jekyll.logger.warn "Warning:", "Site URL does not appear to be set" + false + end + + def url_valid?(url) + Addressable::URI.parse(url) + true + rescue + Jekyll.logger.warn "Warning:", "Cannot parse site URL: #{url}" + false + end + + def url_absolute(url) + return true if Addressable::URI.parse(url).absolute? + Jekyll.logger.warn "Warning:", "Site URL does not appear to be" \ + " absolute: #{url}" + false + end end end end