mirror of https://github.com/freeCodeCamp/devdocs
- Add new filters due changes in the page of Chef. - Rename old filters for old version of Chef.pull/1393/head
parent
6cc5df21ce
commit
949417022a
@ -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
|
||||
class Chef
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
|
||||
def get_name
|
||||
name = at_css('.body h1').content
|
||||
name.remove! "\u{00b6}"
|
||||
name.remove! 'About the '
|
||||
name.remove! 'About '
|
||||
name
|
||||
at_css('h1').content
|
||||
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
|
||||
|
||||
case slug
|
||||
when /automate/
|
||||
'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
|
||||
CLIENT_TYPE_BY_SLUG_END_WITH.each do |key, value|
|
||||
return value if slug.end_with?(key)
|
||||
end
|
||||
'Chef Infra'
|
||||
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
|
||||
|
@ -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
|
Loading…
Reference in new issue