Class: Jekyll::Commands::Doctor

Inherits:
Jekyll::Command show all
Defined in:
lib/jekyll/commands/doctor.rb

Class Method Summary collapse

Methods inherited from Jekyll::Command

add_build_options, configuration_from_options, inherited, process_site, subclasses

Class Method Details

.conflicting_urls(site) ⇒ Object


51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/jekyll/commands/doctor.rb', line 51

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.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

38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jekyll/commands/doctor.rb', line 38

def deprecated_relative_permalinks(site)
  contains_deprecated_pages = false
  site.pages.each do |page|
    if page.uses_relative_permalinks
      Jekyll::Deprecator.deprecation_message "'#{page.path}' uses relative" +
                          " permalinks which will be deprecated in" +
                          " Jekyll v2.0.0 and beyond."
      contains_deprecated_pages = true
    end
  end
  contains_deprecated_pages
end

.healthy?(site) ⇒ Boolean

Returns:

  • (Boolean)

31
32
33
34
35
36
# File 'lib/jekyll/commands/doctor.rb', line 31

def healthy?(site)
  [
    !deprecated_relative_permalinks(site),
    !conflicting_urls(site)
  ].all?
end

.init_with_program(prog) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jekyll/commands/doctor.rb', line 6

def init_with_program(prog)
  prog.command(:doctor) do |c|
    c.syntax 'doctor'
    c.description 'Search site and print specific deprecation warnings'
    c.alias(:hyde)

    c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'

    c.action do |args, options|
      Jekyll::Commands::Doctor.process(options)
    end
  end
end

.process(options) ⇒ Object


20
21
22
23
24
25
26
27
28
29
# File 'lib/jekyll/commands/doctor.rb', line 20

def process(options)
  site = Jekyll::Site.new(configuration_from_options(options))
  site.read

  if healthy?(site)
    Jekyll.logger.info "Your test results", "are in. Everything looks fine."
  else
    abort
  end
end