Add Chef version 16

- Add new filters due changes in the page of Chef.
- Rename old filters for old version of Chef.
pull/1393/head
MasterEnoc 4 years ago
parent 6cc5df21ce
commit 949417022a

@ -2,33 +2,24 @@ module Docs
class Chef class Chef
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
@doc = at_css('div[role="main"]') @doc = at_css('#main-content-col')
css('.headerlink').remove if root_page?
css('img').remove
css('em', 'div.align-center', 'a[href$=".svg"]').each do |node|
node.before(node.children).remove
end end
css('.section').each do |node| css('pre').each do |node|
node.first_element_child['id'] = node['id'] if node['id'] node.remove_attribute('style')
node.before(node.children).remove
end
css('tt').each do |node| if !(node.classes.include?('highlight'))
node.content = node.content.strip node.add_class('highlight')
node.name = 'code' node['data-language'] = 'ruby'
end end
css('table[border]').each do |node|
node.remove_attribute('border')
end end
css('div[class*="highlight-"]').each do |node| css('#feedback').remove
node.content = node.content.strip
node.name = 'pre' css('.mini-toc-header').remove
node['data-language'] = node['class'][/highlight\-(\w+)/, 1]
end
doc doc
end end

@ -0,0 +1,37 @@
module Docs
class Chef
class CleanHtmlOldFilter < Filter
def call
@doc = at_css('div[role="main"]')
css('.headerlink').remove
css('em', 'div.align-center', 'a[href$=".svg"]').each do |node|
node.before(node.children).remove
end
css('.section').each do |node|
node.first_element_child['id'] = node['id'] if node['id']
node.before(node.children).remove
end
css('tt').each do |node|
node.content = node.content.strip
node.name = 'code'
end
css('table[border]').each do |node|
node.remove_attribute('border')
end
css('div[class*="highlight-"]').each do |node|
node.content = node.content.strip
node.name = 'pre'
node['data-language'] = node['class'][/highlight\-(\w+)/, 1]
end
doc
end
end
end
end

@ -1,68 +1,34 @@
module Docs module Docs
class Chef class Chef
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
name = at_css('.body h1').content at_css('h1').content
name.remove! "\u{00b6}"
name.remove! 'About the '
name.remove! 'About '
name
end end
CLIENT_TYPE_BY_SLUG_END_WITH = {
'knife_common_options' => 'Workflow Tools',
'knife_using' => 'Workflow Tools',
'resource_common' => 'Cookbooks',
'config_rb_knife_optional_settings' => 'Workflow Tools',
'knife_index_rebuild' => 'Workflow Tools',
'handlers' => 'Extend Chef',
'dsl_recipe' => 'Extend Chef',
'resource' => 'Extend Chef'
}
SERVER_TYPE_BY_SLUG_END_WITH = {
'auth' => 'Theory & Concepts',
'install_server' => 'Setup & Config',
'install_server_pre' => 'Setup & Config',
'config_rb_server_optional_settings' => 'Manage the Server',
'ctl_chef_server' => 'Manage the Server'
}
def get_type def get_type
if server_page?
SERVER_TYPE_BY_SLUG_END_WITH.each do |key, value|
return "Chef Server / #{value}" if slug.end_with?(key)
end
else
CLIENT_TYPE_BY_SLUG_END_WITH.each do |key, value|
return value if slug.end_with?(key)
end
end
path = nav_path
path.delete('Reference')
path = path[0..0]
path.unshift('Chef Server') if server_page?
type = path.join(' / ') case slug
type.sub 'Cookbooks / Cookbook', 'Cookbooks /' when /automate/
type 'Chef Automate'
when /compliance/
'Chef Compliance'
when /desktop/
'Chef Desktop'
when /habitat/
'Chef Habitat'
when /inspec/
'Chef InSpec'
when /workstation/
'Chef Workstation'
when /effortless/
'Effortless Pattern'
else
'Chef Infra'
end end
def server_page?
slug.start_with?(context[:server_path])
end end
def nav_path
node = at_css(".nav-docs a[href='#{result[:path].split('/').last}']")
path = []
until node['class'] && node['class'].include?('main-item')
path.unshift(node.first_element_child.content.strip) if node['class'] && node['class'].include?('has-sub-items')
node = node.parent
end
path.unshift(node.first_element_child.content.strip)
path
end
end end
end end
end end

@ -0,0 +1,68 @@
module Docs
class Chef
class EntriesOldFilter < Docs::EntriesFilter
def get_name
name = at_css('.body h1').content
name.remove! "\u{00b6}"
name.remove! 'About the '
name.remove! 'About '
name
end
CLIENT_TYPE_BY_SLUG_END_WITH = {
'knife_common_options' => 'Workflow Tools',
'knife_using' => 'Workflow Tools',
'resource_common' => 'Cookbooks',
'config_rb_knife_optional_settings' => 'Workflow Tools',
'knife_index_rebuild' => 'Workflow Tools',
'handlers' => 'Extend Chef',
'dsl_recipe' => 'Extend Chef',
'resource' => 'Extend Chef'
}
SERVER_TYPE_BY_SLUG_END_WITH = {
'auth' => 'Theory & Concepts',
'install_server' => 'Setup & Config',
'install_server_pre' => 'Setup & Config',
'config_rb_server_optional_settings' => 'Manage the Server',
'ctl_chef_server' => 'Manage the Server'
}
def get_type
if server_page?
SERVER_TYPE_BY_SLUG_END_WITH.each do |key, value|
return "Chef Server / #{value}" if slug.end_with?(key)
end
else
CLIENT_TYPE_BY_SLUG_END_WITH.each do |key, value|
return value if slug.end_with?(key)
end
end
path = nav_path
path.delete('Reference')
path = path[0..0]
path.unshift('Chef Server') if server_page?
type = path.join(' / ')
type.sub 'Cookbooks / Cookbook', 'Cookbooks /'
type
end
def server_page?
slug.start_with?(context[:server_path])
end
def nav_path
node = at_css(".nav-docs a[href='#{result[:path].split('/').last}']")
path = []
until node['class'] && node['class'].include?('main-item')
path.unshift(node.first_element_child.content.strip) if node['class'] && node['class'].include?('has-sub-items')
node = node.parent
end
path.unshift(node.first_element_child.content.strip)
path
end
end
end
end

@ -1,20 +1,16 @@
module Docs module Docs
class Chef < UrlScraper class Chef < UrlScraper
self.type = 'sphinx_simple' self.type = 'sphinx_simple'
self.base_url = 'https://docs-archive.chef.io/release/' self.base_url = 'https://docs.chef.io'
self.links = { self.links = {
home: 'https://www.chef.io/', home: 'https://www.chef.io/',
code: 'https://github.com/chef/chef' code: 'https://github.com/chef/chef'
} }
html_filters.push 'chef/entries', 'chef/clean_html'
options[:skip_patterns] = [ options[:skip_patterns] = [
/\A[^\/]+\/\z/, /release_notes/,
/\A[^\/]+\/index\.html\z/, /feedback/
/\A[^\/]+\/release_notes\.html\z/, ]
/\Aserver[^\/]+\/chef_overview\.html\z/,
/\A[\d\-]+\/server_components\.html\z/ ]
options[:attribution] = <<-HTML options[:attribution] = <<-HTML
&copy; Chef Software, Inc.<br> &copy; Chef Software, Inc.<br>
@ -24,12 +20,38 @@ module Docs
We are not affiliated with, endorsed or sponsored by Chef Inc. We are not affiliated with, endorsed or sponsored by Chef Inc.
HTML HTML
version '16' do
self.release = '16.7.61'
options[:container] = '.off-canvas-wrapper'
options[:skip] = [
'/automate/api/',
'/habitat/supervisor_api/',
'/habitat/builder_api/'
]
html_filters.push 'chef/entries', 'chef/clean_html'
end
version '12' do version '12' do
self.release = '12.13' self.release = '12.13'
self.base_url = 'https://docs-archive.chef.io/release/'
html_filters.push 'chef/entries_old', 'chef/clean_html_old'
options[:client_path] = client_path = '12-13' options[:client_path] = client_path = '12-13'
options[:server_path] = server_path = 'server_12-8' options[:server_path] = server_path = 'server_12-8'
options[:skip_patterns] = [
/\A[^\/]+\/\z/,
/\A[^\/]+\/index\.html\z/,
/\A[^\/]+\/release_notes\.html\z/,
/\Aserver[^\/]+\/chef_overview\.html\z/,
/\A[\d\-]+\/server_components\.html\z/
]
self.root_path = "#{client_path}/chef_overview.html" self.root_path = "#{client_path}/chef_overview.html"
self.initial_paths = ["#{server_path}/server_components.html"] self.initial_paths = ["#{server_path}/server_components.html"]
@ -38,10 +60,21 @@ module Docs
version '11' do version '11' do
self.release = '11.18' self.release = '11.18'
self.base_url = 'https://docs-archive.chef.io/release/'
html_filters.push 'chef/entries_old', 'chef/clean_html_old'
options[:client_path] = client_path = '11-18' options[:client_path] = client_path = '11-18'
options[:server_path] = server_path = 'server_12-8' options[:server_path] = server_path = 'server_12-8'
options[:skip_patterns] = [
/\A[^\/]+\/\z/,
/\A[^\/]+\/index\.html\z/,
/\A[^\/]+\/release_notes\.html\z/,
/\Aserver[^\/]+\/chef_overview\.html\z/,
/\A[\d\-]+\/server_components\.html\z/
]
self.root_path = "#{client_path}/chef_overview.html" self.root_path = "#{client_path}/chef_overview.html"
self.initial_paths = ["#{server_path}/server_components.html"] self.initial_paths = ["#{server_path}/server_components.html"]
@ -52,5 +85,6 @@ module Docs
doc = fetch_doc('https://downloads.chef.io/products/infra', opts) doc = fetch_doc('https://downloads.chef.io/products/infra', opts)
doc.at_css('#versions > option').content.strip doc.at_css('#versions > option').content.strip
end end
end end
end end

Loading…
Cancel
Save