diff --git a/lib/docs/filters/docker/clean_html.rb b/lib/docs/filters/docker/clean_html.rb index 4237c7b7..cb1557a6 100644 --- a/lib/docs/filters/docker/clean_html.rb +++ b/lib/docs/filters/docker/clean_html.rb @@ -7,10 +7,12 @@ module Docs return doc end - @doc = at_css('#content') + @doc = at_css('#DocumentationText') at_css('h2').name = 'h1' unless at_css('h1') + css('.anchorLink').remove + css('pre').each do |node| node.content = node.content end diff --git a/lib/docs/filters/docker/clean_html_old.rb b/lib/docs/filters/docker/clean_html_old.rb new file mode 100644 index 00000000..cbbc1ef0 --- /dev/null +++ b/lib/docs/filters/docker/clean_html_old.rb @@ -0,0 +1,22 @@ +module Docs + class Docker + class CleanHtmlOldFilter < Filter + def call + if root_page? + doc.inner_html = "

Docker Documentation

" + return doc + end + + @doc = at_css('#content') + + at_css('h2').name = 'h1' unless at_css('h1') + + css('pre').each do |node| + node.content = node.content + end + + doc + end + end + end +end diff --git a/lib/docs/filters/docker/entries.rb b/lib/docs/filters/docker/entries.rb index 089f9e16..1b8ec468 100644 --- a/lib/docs/filters/docker/entries.rb +++ b/lib/docs/filters/docker/entries.rb @@ -2,14 +2,15 @@ module Docs class Docker class EntriesFilter < Docs::EntriesFilter def get_name - name = nav_link ? nav_link.content.strip : at_css('#content h1').content.strip + return 'Engine' if subpath == 'engine/' + + name = nav_link.content.strip name.capitalize! if name == 'exoscale' if name =~ /\A[a-z\-\s]+\z/ name.prepend 'docker ' if subpath =~ /engine\/reference\/commandline\/./ name.prepend 'docker-compose ' if subpath =~ /compose\/reference\/./ name.prepend 'docker-machine ' if subpath =~ /machine\/reference\/./ - name.prepend 'swarm ' if subpath =~ /swarm\/reference\/./ && name != 'swarm' else name << " (#{product})" if name !~ /#{product}/i end @@ -18,16 +19,13 @@ module Docs end def get_type - unless nav_link - return 'Engine: User guide' if subpath.start_with?('engine/userguide') - return 'Engine: Secure' if subpath.start_with?('engine/security') - return 'Engine' if subpath == 'engine/' - end + return 'Engine' if subpath == 'engine/' - type = nav_link.ancestors('article').to_a.reverse.to_a[0..1].map do |node| - node.at_css('> button').content.strip + type = nav_link.ancestors('.menu-open').to_a.reverse.to_a[0..1].map do |node| + node.at_css('> a').content.strip end.join(': ') + type = self.name if type.empty? type.remove! %r{\ADocker } type.remove! %r{ Engine} type.sub! %r{Command[\-\s]line reference}i, 'CLI' @@ -37,14 +35,14 @@ module Docs def nav_link return @nav_link if defined?(@nav_link) - @nav_link = at_css('#multiple .active') + @nav_link = at_css('.currentPage') unless @nav_link - link = at_css('#content li a') + link = at_css('#DocumentationText li a') return unless link - link = at_css("#multiple a[href='#{link['href']}']") + link = at_css(".docsidebarnav_section a[href='#{link['href']}']") return unless link - @nav_link = link.ancestors('article').first.at_css('button') + @nav_link = link.ancestors('.menu-closed').first.at_css('a') end @nav_link diff --git a/lib/docs/filters/docker/entries_old.rb b/lib/docs/filters/docker/entries_old.rb new file mode 100644 index 00000000..01baf4ae --- /dev/null +++ b/lib/docs/filters/docker/entries_old.rb @@ -0,0 +1,56 @@ +module Docs + class Docker + class EntriesOldFilter < Docs::EntriesFilter + def get_name + name = nav_link ? nav_link.content.strip : at_css('#content h1').content.strip + name.capitalize! if name == 'exoscale' + + if name =~ /\A[a-z\-\s]+\z/ + name.prepend 'docker ' if subpath =~ /engine\/reference\/commandline\/./ + name.prepend 'docker-compose ' if subpath =~ /compose\/reference\/./ + name.prepend 'docker-machine ' if subpath =~ /machine\/reference\/./ + name.prepend 'swarm ' if subpath =~ /swarm\/reference\/./ && name != 'swarm' + else + name << " (#{product})" if name !~ /#{product}/i + end + + name + end + + def get_type + unless nav_link + return 'Engine: User guide' if subpath.start_with?('engine/userguide') + end + + type = nav_link.ancestors('article').to_a.reverse.to_a[0..1].map do |node| + node.at_css('> button').content.strip + end.join(': ') + + type.remove! %r{\ADocker } + type.remove! %r{ Engine} + type.sub! %r{Command[\-\s]line reference}i, 'CLI' + type = 'Engine: Reference' if type == 'Engine: reference' + type + end + + def nav_link + return @nav_link if defined?(@nav_link) + @nav_link = at_css('#multiple .active') + + unless @nav_link + link = at_css('#content li a') + return unless link + link = at_css("#multiple a[href='#{link['href']}']") + return unless link + @nav_link = link.ancestors('article').first.at_css('button') + end + + @nav_link + end + + def product + @product ||= subpath.split('/').first.capitalize + end + end + end +end diff --git a/lib/docs/scrapers/docker.rb b/lib/docs/scrapers/docker.rb index 635247f3..969dace2 100644 --- a/lib/docs/scrapers/docker.rb +++ b/lib/docs/scrapers/docker.rb @@ -6,20 +6,37 @@ module Docs code: 'https://github.com/docker/docker' } - html_filters.push 'docker/entries', 'docker/clean_html' - - options[:container] = '#docs' options[:trailing_slash] = true - options[:only_patterns] = [ - /\Aengine\//, - /\Acompose\//, - /\Amachine\//, - /\Aswarm\// - ] - options[:skip] = %w(swarm/scheduler/) + options[:only_patterns] = [/\Aengine\//, /\Acompose\//, /\Amachine\//] + + options[:skip] = %w( + swarm/scheduler/ + swarm/swarm_at_scale/ + swarm/reference/ + engine/installation/linux/ + engine/installation/cloud/ + engine/installation/ + engine/tutorials/ + engine/userguide/ + engine/extend/ + engine/examples/ + engine/reference/ + engine/reference/api/ + engine/security/ + engine/security/trust/ + engine/getstarted/linux_install_help/ + machine/reference/ + machine/drivers/ + machine/examples/ + compose/reference/ + ) # index pages + options[:replace_paths] = { - 'engine/installation/ubuntulinux/' => 'engine/installation/linux/ubuntulinux/' + 'engine/installation/ubuntulinux/' => 'engine/installation/linux/ubuntulinux/', + 'engine/userguide/networking/dockernetworks/' => 'engine/userguide/networking/', + 'engine/reference/logging/overview/' => 'engine/admin/logging/overview/', + 'engine/userguide/dockervolumes/' => 'engine/tutorials/dockervolumes/' } options[:attribution] = <<-HTML @@ -29,14 +46,33 @@ module Docs Docker, Inc. and other parties may also have trademark rights in other terms used herein. HTML + version '1.12' do + self.release = '1.12' + self.base_url = 'https://docs.docker.com/' + + html_filters.push 'docker/entries', 'docker/clean_html' + + options[:container] = '.container-fluid .row' + end + version '1.11' do self.release = '1.11' self.base_url = "https://docs.docker.com/v#{self.version}/" + + html_filters.push 'docker/entries_old', 'docker/clean_html_old' + + options[:container] = '#docs' + options[:only_patterns] << /\Aswarm\// end version '1.10' do self.release = '1.10' self.base_url = "https://docs.docker.com/v#{self.version}/" + + html_filters.push 'docker/entries_old', 'docker/clean_html_old' + + options[:container] = '#docs' + options[:only_patterns] << /\Aswarm\// end end end