Skip to content

Commit

Permalink
Add URL checks to Doctor (#5760)
Browse files Browse the repository at this point in the history
Merge pull request 5760
  • Loading branch information
pathawks authored and jekyllbot committed Jul 18, 2017
1 parent 2b28f9f commit da65e94
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/jekyll/commands/doctor.rb
@@ -1,3 +1,5 @@
require "addressable/uri"

module Jekyll
module Commands
class Doctor < Command
Expand Down Expand Up @@ -36,6 +38,7 @@ def healthy?(site)
!deprecated_relative_permalinks(site),
!conflicting_urls(site),
!urls_only_differ_by_case(site),
proper_site_url?(site),
].all?
end

Expand Down Expand Up @@ -91,6 +94,15 @@ 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),
].all?
end

private
def collect_urls(urls, things, destination)
things.each do |thing|
Expand All @@ -110,6 +122,29 @@ 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:", "You didn't set an URL in the config file, "\
"you may encounter problems with some plugins."
false
end

def url_valid?(url)
Addressable::URI.parse(url)
true
rescue
Jekyll.logger.warn "Warning:", "The site URL does not seem to be valid, "\
"check the value of `url` in your config file."
false
end

def url_absolute(url)
return true if Addressable::URI.parse(url).absolute?
Jekyll.logger.warn "Warning:", "Your site URL does not seem to be absolute, "\
"check the value of `url` in your config file."
false
end
end
end
end
Expand Down

0 comments on commit da65e94

Please sign in to comment.