Sha256: cb9ed7f2924b7eac2e408adbb82a865c7c5bb81c52a6f35d7c2286b343d1e83d

Contents?: true

Size: 1.87 KB

Versions: 13

Compression:

Stored size: 1.87 KB

Contents

module Jekyll
  module Commands
    class Doctor < Command
      class << self
        def process(options)
          site = Jekyll::Site.new(options)
          site.read

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

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

        def deprecated_relative_permalinks(site)
          contains_deprecated_pages = false
          site.pages.each do |page|
            if page.uses_relative_permalinks
              Jekyll.logger.warn "Deprecation:", "'#{page.path}' uses relative" +
                                  " permalinks which will be deprecated in" +
                                  " Jekyll v1.2 and beyond."
              contains_deprecated_pages = true
            end
          end
          contains_deprecated_pages
        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.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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
jekyll-1.5.1 lib/jekyll/commands/doctor.rb
jekyll-1.5.0 lib/jekyll/commands/doctor.rb
jekyll-2.0.0.alpha.1 lib/jekyll/commands/doctor.rb
jekyll-1.4.3 lib/jekyll/commands/doctor.rb
jekyll-1.4.2 lib/jekyll/commands/doctor.rb
jekyll-1.4.1 lib/jekyll/commands/doctor.rb
jekyll-1.4.0 lib/jekyll/commands/doctor.rb
jekyll-1.3.1 lib/jekyll/commands/doctor.rb
jekyll-1.3.0 lib/jekyll/commands/doctor.rb
jekyll-1.3.0.rc lib/jekyll/commands/doctor.rb
monad-0.0.3 lib/jekyll/commands/doctor.rb
jekyll-1.2.1 lib/jekyll/commands/doctor.rb
jekyll-1.2.0 lib/jekyll/commands/doctor.rb