Sha256: 0672d749fd94dc6926e4fc30f3e68e98d5b02504bb3f1b346bb37563d25b89b6

Contents?: true

Size: 928 Bytes

Versions: 4

Compression:

Stored size: 928 Bytes

Contents

require "net/http"
require "nokogiri"

module JekyllSort
  class Reorder
    def initialize(options)
      @options = options
    end

    def run
      check_in_docs_folder!

      uri = URI('http://localhost:4000/docs/')
      begin
        body = Net::HTTP.get(uri) # => String
      rescue Errno::ECONNREFUSED => e
        puts e
        puts "ERROR: Please make sure the jekyll server is running and server docs.  You can use:"
        puts "  bin/web"
      end

      PrevNext.new.create
      Page.reset_all

      doc = Nokogiri::HTML(body)
      links = doc.search('.content-nav a')
      links.each_with_index do |link, i|
        page = Page.new(link[:href], i+1)
        page.update
      end
    end

    def check_in_docs_folder!
      parent_folder = File.basename(Dir.pwd)
      if parent_folder != "docs"
        puts "Please run this command within the docs folder"
        exit 1
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jekyll-sort-0.3.1 lib/jekyll_sort/reorder.rb
jekyll-sort-0.3.0 lib/jekyll_sort/reorder.rb
jekyll-sort-0.2.0 lib/jekyll_sort/reorder.rb
jekyll-sort-0.1.0 lib/jekyll_sort/reorder.rb