Skip to content

Commit

Permalink
Add URL checks to Doctor
Browse files Browse the repository at this point in the history
  • Loading branch information
pathawks committed Jan 12, 2017
1 parent 8ae2673 commit 8875bdf
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion lib/jekyll/commands/doctor.rb
@@ -1,3 +1,5 @@
require "addressable/uri"

module Jekyll
module Commands
class Doctor < Command
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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|
Expand All @@ -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
Expand Down

0 comments on commit 8875bdf

Please sign in to comment.