From 437eb8dd542e2a26b72a90ff723ead51aa719a9b Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Mon, 4 Sep 2017 12:08:40 -0400 Subject: [PATCH] Update Docker documentation (17.06) --- .../templates/pages/about_tmpl.coffee | 4 +- lib/docs/filters/docker/clean_html.rb | 8 +- lib/docs/filters/docker/clean_html_old.rb | 17 ++- .../filters/docker/clean_html_very_old.rb | 22 ++++ lib/docs/filters/docker/entries.rb | 37 +----- lib/docs/filters/docker/entries_old.rb | 51 +++++--- lib/docs/filters/docker/entries_very_old.rb | 56 ++++++++ lib/docs/scrapers/docker.rb | 123 ++++++++++++------ 8 files changed, 230 insertions(+), 88 deletions(-) create mode 100644 lib/docs/filters/docker/clean_html_very_old.rb create mode 100644 lib/docs/filters/docker/entries_very_old.rb diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 28884fc2..fc68a1cf 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -210,9 +210,9 @@ credits = [ 'https://raw.githubusercontent.com/django/django/master/LICENSE' ], [ 'Docker', - '2013-2016 Docker, Inc.
Docker and the Docker logo are trademarks of Docker, Inc.', + '2017 Docker, Inc.
Docker and the Docker logo are trademarks of Docker, Inc.', 'Apache', - 'https://raw.githubusercontent.com/docker/docker/master/LICENSE' + 'https://raw.githubusercontent.com/docker/docker.github.io/master/LICENSE' ], [ 'Dojo', '2005-2017 JS Foundation', diff --git a/lib/docs/filters/docker/clean_html.rb b/lib/docs/filters/docker/clean_html.rb index 4253d51a..49a12282 100644 --- a/lib/docs/filters/docker/clean_html.rb +++ b/lib/docs/filters/docker/clean_html.rb @@ -7,7 +7,7 @@ module Docs return doc end - @doc = at_css('#DocumentationText') + @doc = at_css('main .section') at_css('h2').name = 'h1' unless at_css('h1') @@ -30,8 +30,14 @@ module Docs node.content = node.content.gsub(/\s+/, ' ').strip end + css('> span').each do |node| + node.name = 'p' + node.remove_attribute('style') + end + doc end end end end + diff --git a/lib/docs/filters/docker/clean_html_old.rb b/lib/docs/filters/docker/clean_html_old.rb index cbbc1ef0..2c572671 100644 --- a/lib/docs/filters/docker/clean_html_old.rb +++ b/lib/docs/filters/docker/clean_html_old.rb @@ -7,12 +7,27 @@ module Docs return doc end - @doc = at_css('#content') + @doc = at_css('#DocumentationText') at_css('h2').name = 'h1' unless at_css('h1') + css('.anchorLink', '.reading-time', 'hr', '> div[style*="margin-top"]:last-child').remove + + css('h1 + h1').each do |node| + node.name = 'h2' + end + css('pre').each do |node| node.content = node.content + node['data-language'] = node.parent['class'][/language-(\w+)/, 1] if node.parent['class'] + end + + css('div.highlighter-rouge').each do |node| + node.before(node.children).remove + end + + css('code.highlighter-rouge').each do |node| + node.content = node.content.gsub(/\s+/, ' ').strip end doc diff --git a/lib/docs/filters/docker/clean_html_very_old.rb b/lib/docs/filters/docker/clean_html_very_old.rb new file mode 100644 index 00000000..e0a9fedc --- /dev/null +++ b/lib/docs/filters/docker/clean_html_very_old.rb @@ -0,0 +1,22 @@ +module Docs + class Docker + class CleanHtmlVeryOldFilter < 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 16762b8d..63285e0c 100644 --- a/lib/docs/filters/docker/entries.rb +++ b/lib/docs/filters/docker/entries.rb @@ -4,7 +4,8 @@ module Docs NAME_BY_SUBPATH = { 'engine/' => 'Engine', 'compose/' => 'Compose', - 'machine/' => 'Machine' + 'machine/' => 'Machine', + 'notary/' => 'Notary' } def get_name @@ -19,52 +20,26 @@ module Docs name.prepend 'docker-compose ' if subpath =~ /compose\/reference\/./ name.prepend 'docker-machine ' if subpath =~ /machine\/reference\/./ else - name << " (#{product})" if name !~ /#{product}/i + name << " (#{product})" if name !~ /#{product}/i && !subpath.start_with?('get-started') end name end - TYPE_BY_SUBPATH = { - 'engine/' => 'Engine', - 'compose/' => 'Compose', - 'machine/' => 'Machine' - } - def get_type - return TYPE_BY_SUBPATH[subpath] if TYPE_BY_SUBPATH[subpath] + return NAME_BY_SUBPATH[subpath] if NAME_BY_SUBPATH[subpath] + return 'Get Started' if subpath.start_with?('get-started') return 'Engine: CLI' if subpath.start_with?('engine/reference/commandline/') return 'Engine: Admin Guide' if subpath.start_with?('engine/admin/') return 'Engine: Security' if subpath.start_with?('engine/security/') return 'Engine: Extend' if subpath.start_with?('engine/extend/') - return 'Engine: Get Started' if subpath.start_with?('engine/getstarted') return 'Engine: Tutorials' if subpath.start_with?('engine/tutorials/') - return product if !nav_link && subpath =~ /\A\w+\/[\w\-]+\/\z/ - - leaves = nav_link.ancestors('li.leaf').reverse - return product if leaves.length <= 2 - - type = leaves[0..1].map { |node| node.at_css('> a').content.strip }.join(': ') - type.remove! %r{\ADocker } - type.remove! ' Engine' - type.sub! %r{Command[\-\s]line reference}i, 'CLI' - type.sub! 'CLI reference', 'CLI' - type + product end def nav_link return @nav_link if defined?(@nav_link) @nav_link = at_css('.currentPage') - - unless @nav_link - link = at_css('#DocumentationText li a') - return unless link - link = at_css(".docsidebarnav_section a[href='#{link['href']}']") - return unless link - @nav_link = link.ancestors('.menu-closed').first.at_css('a') - end - - @nav_link end def product diff --git a/lib/docs/filters/docker/entries_old.rb b/lib/docs/filters/docker/entries_old.rb index 01baf4ae..fdf17958 100644 --- a/lib/docs/filters/docker/entries_old.rb +++ b/lib/docs/filters/docker/entries_old.rb @@ -1,15 +1,23 @@ module Docs class Docker class EntriesOldFilter < Docs::EntriesFilter + NAME_BY_SUBPATH = { + 'engine/' => 'Engine', + 'compose/' => 'Compose', + 'machine/' => 'Machine' + } + def get_name - name = nav_link ? nav_link.content.strip : at_css('#content h1').content.strip + return NAME_BY_SUBPATH[subpath] if NAME_BY_SUBPATH[subpath] + return at_css('h1').content unless nav_link + + name = nav_link.content.strip name.capitalize! if name == 'exoscale' + name.remove! ' (base command)' 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-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 @@ -17,32 +25,43 @@ module Docs name end + TYPE_BY_SUBPATH = { + 'engine/' => 'Engine', + 'compose/' => 'Compose', + 'machine/' => 'Machine' + } + def get_type - unless nav_link - return 'Engine: User guide' if subpath.start_with?('engine/userguide') - end + return TYPE_BY_SUBPATH[subpath] if TYPE_BY_SUBPATH[subpath] + return 'Engine: CLI' if subpath.start_with?('engine/reference/commandline/') + return 'Engine: Admin Guide' if subpath.start_with?('engine/admin/') + return 'Engine: Security' if subpath.start_with?('engine/security/') + return 'Engine: Extend' if subpath.start_with?('engine/extend/') + return 'Engine: Get Started' if subpath.start_with?('engine/getstarted') + return 'Engine: Tutorials' if subpath.start_with?('engine/tutorials/') + return product if !nav_link && subpath =~ /\A\w+\/[\w\-]+\/\z/ - type = nav_link.ancestors('article').to_a.reverse.to_a[0..1].map do |node| - node.at_css('> button').content.strip - end.join(': ') + leaves = nav_link.ancestors('li.leaf').reverse + return product if leaves.length <= 2 + type = leaves[0..1].map { |node| node.at_css('> a').content.strip }.join(': ') type.remove! %r{\ADocker } - type.remove! %r{ Engine} + type.remove! ' Engine' type.sub! %r{Command[\-\s]line reference}i, 'CLI' - type = 'Engine: Reference' if type == 'Engine: reference' + type.sub! 'CLI reference', 'CLI' type end 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_very_old.rb b/lib/docs/filters/docker/entries_very_old.rb new file mode 100644 index 00000000..25850245 --- /dev/null +++ b/lib/docs/filters/docker/entries_very_old.rb @@ -0,0 +1,56 @@ +module Docs + class Docker + class EntriesVeryOldFilter < 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 f6c3a12d..a1a6345b 100644 --- a/lib/docs/scrapers/docker.rb +++ b/lib/docs/scrapers/docker.rb @@ -8,82 +8,131 @@ module Docs options[:trailing_slash] = true - options[:only_patterns] = [/\Aengine\//, /\Acompose\//, /\Amachine\//] - options[:skip_patterns] = [/\Aengine\/api\/v/, /\Aengine\/installation/] - options[:skip] = %w( - / - engine/userguide/ - engine/examples/ - engine/reference/ - engine/reference/api/ - engine/reference/api/docker_remote_api_v1.24/ - engine/getstarted/linux_install_help/ - machine/reference/ - machine/drivers/ - machine/examples/ - compose/reference/ - ) - options[:fix_urls] = ->(url) do url.sub! %r{\.md/?(?=#|\z)}, '/' url.sub! '/index/', '/' url end - options[:replace_paths] = { - 'engine/userguide/networking/dockernetworks/' => 'engine/userguide/networking/', - 'engine/userguide/dockervolumes/' => 'engine/tutorials/dockervolumes/', - 'engine/reference/logging/overview/' => 'engine/admin/logging/overview/', - 'engine/reference/commandline/daemon/' => 'engine/reference/commandline/dockerd/', - 'engine/reference/commandline/' => 'engine/reference/commandline/docker/', - 'engine/reference/api/docker_remote_api/' => 'engine/api/', - 'engine/swarm/how-swarm-mode-works/' => 'engine/swarm/how-swarm-mode-works/nodes/', - 'engine/tutorials/dockerizing/' => 'engine/getstarted/step_one/', - 'engine/tutorials/usingdocker/' => 'engine/getstarted/step_three/', - 'engine/tutorials/dockerimages/' => 'engine/getstarted/step_four/', - 'engine/tutorials/dockerrepos/' => 'engine/getstarted/step_six/' - } - options[:attribution] = <<-HTML - © 2013–2016 Docker, Inc.
+ © 2017 Docker, Inc.
Licensed under the Apache License, Version 2.0.
Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.
Docker, Inc. and other parties may also have trademark rights in other terms used herein. HTML - version '1.13' do - self.release = '1.13' + version '17' do + self.release = '17.06' self.base_url = 'https://docs.docker.com/' html_filters.push 'docker/entries', 'docker/clean_html' + options[:container] = '.wrapper .container-fluid .row' + + options[:only_patterns] = [/\Aget-started\//, /\Aengine\//, /\Acompose\//, /\Amachine\//, /\Anotary\//] + options[:skip_patterns] = [/\Aengine\/api\/v/, /glossary/, /docker-ee/] + + options[:replace_paths] = { + 'engine/installation/linux/docker-ee/linux-postinstall/' => 'engine/installation/linux/linux-postinstall/', + 'engine/installation/linux/docker-ee/' => 'engine/installation/', + 'engine/installation/linux/docker-ce/' => 'engine/installation/', + 'engine/installation/linux/' => 'engine/installation/', + 'engine/installation/windows/' => 'engine/installation/', + 'engine/userguide/intro/' => 'engine/userguide/', + 'engine/tutorials/dockervolumes/' => 'engine/admin/volumes/volumes/', + 'engine/getstarted/' => 'get-started/', + 'engine/tutorials/dockerimages/' => 'get-started/', + 'engine/tutorials/dockerrepos/' => 'get-started/', + 'engine/admin/host_integration/' => 'engine/admin/start-containers-automatically/', + 'engine/installation/linux/rhel/' => 'engine/installation/linux/docker-ee/rhel/', + 'engine/installation/linux/ubuntulinux/' => 'engine/installation/linux/docker-ee/ubuntu/', + 'engine/installation/linux/suse/' => 'engine/installation/linux/docker-ee/suse/', + 'engine/admin/logging/' => 'engine/admin/logging/view_container_logs/', + 'engine/swarm/how-swarm-mode-works/' => 'engine/swarm/how-swarm-mode-works/nodes/', + 'engine/installation/binaries/' => 'engine/installation/linux/docker-ce/binaries/', + 'engine/reference/commandline/' => 'engine/reference/commandline/docker/', + 'engine/reference/api/' => 'engine/api/', + 'engine/userguide/dockervolumes/' => 'engine/admin/volumes/volumes/', + 'engine/understanding-docker/' => 'engine/docker-overview/', + 'engine/reference/commandline/swarm_join_token/' => 'engine/reference/commandline/swarm_join-token/', + 'engine/api/getting-started/' => 'engine/api/get-started/', + } + end + + module OldOptions + def self.included(klass) + klass.options[:only_patterns] = [/\Aengine\//, /\Acompose\//, /\Amachine\//] + klass.options[:skip_patterns] = [/\Aengine\/api\/v/, /\Aengine\/installation/] + klass.options[:skip] = %w( + / + engine/userguide/ + engine/examples/ + engine/reference/ + engine/reference/api/ + engine/reference/api/docker_remote_api_v1.24/ + engine/getstarted/linux_install_help/ + machine/reference/ + machine/drivers/ + machine/examples/ + compose/reference/ + ) + klass.options[:replace_paths] = { + 'engine/userguide/networking/dockernetworks/' => 'engine/userguide/networking/', + 'engine/userguide/dockervolumes/' => 'engine/tutorials/dockervolumes/', + 'engine/reference/logging/overview/' => 'engine/admin/logging/overview/', + 'engine/reference/commandline/daemon/' => 'engine/reference/commandline/dockerd/', + 'engine/reference/commandline/' => 'engine/reference/commandline/docker/', + 'engine/reference/api/docker_remote_api/' => 'engine/api/', + 'engine/swarm/how-swarm-mode-works/' => 'engine/swarm/how-swarm-mode-works/nodes/', + 'engine/tutorials/dockerizing/' => 'engine/getstarted/step_one/', + 'engine/tutorials/usingdocker/' => 'engine/getstarted/step_three/', + 'engine/tutorials/dockerimages/' => 'engine/getstarted/step_four/', + 'engine/tutorials/dockerrepos/' => 'engine/getstarted/step_six/' + } + end + end + + version '1.13' do + include OldOptions + + self.release = '1.13' + self.base_url = "https://docs.docker.com/v#{self.version}/" + + html_filters.push 'docker/entries_old', 'docker/clean_html_old' + options[:container] = '.container-fluid .row' end version '1.12' do + include OldOptions + self.release = '1.12' - # self.base_url = 'https://docs.docker.com/' + self.base_url = "https://docs.docker.com/v#{self.version}/" - html_filters.push 'docker/entries', 'docker/clean_html' + html_filters.push 'docker/entries_old', 'docker/clean_html_old' options[:container] = '.container-fluid .row' end version '1.11' do + include OldOptions + self.release = '1.11' self.base_url = "https://docs.docker.com/v#{self.version}/" - html_filters.push 'docker/entries_old', 'docker/clean_html_old' + html_filters.push 'docker/entries_very_old', 'docker/clean_html_very_old' options[:container] = '#docs' options[:only_patterns] << /\Aswarm\// end version '1.10' do + include OldOptions + self.release = '1.10' self.base_url = "https://docs.docker.com/v#{self.version}/" - html_filters.push 'docker/entries_old', 'docker/clean_html_old' + html_filters.push 'docker/entries_very_old', 'docker/clean_html_very_old' options[:container] = '#docs' options[:only_patterns] << /\Aswarm\//