Merge branch 'master' into deploy

* master:
  Add ParseCfEmail filter to the default stack used by all scrapers
  Convert the `decode_cloudflare_email` helper to a dedicated filter class
pull/821/head
Thibaut Courouble 7 years ago
commit 73c9941bed

@ -91,17 +91,6 @@ module Docs
super super
end end
def decode_cloudflare_email(str)
mask = "0x#{str[0..1]}".hex | 0
result = ''
str.chars.drop(2).each_slice(2) do |slice|
result += "%" + "0#{("0x#{slice.join}".hex ^ mask).to_s(16)}"[-2..-1]
end
URI.decode(result)
end
def clean_path(path) def clean_path(path)
path = path.gsub %r{[!;:]}, '-' path = path.gsub %r{[!;:]}, '-'
path = path.gsub %r{\+}, '_plus_' path = path.gsub %r{\+}, '_plus_'

@ -41,7 +41,7 @@ module Docs
self.html_filters = FilterStack.new self.html_filters = FilterStack.new
self.text_filters = FilterStack.new self.text_filters = FilterStack.new
html_filters.push 'apply_base_url', 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths' html_filters.push 'apply_base_url', 'container', 'clean_html', 'normalize_urls', 'internal_urls', 'normalize_paths', 'parse_cf_email'
text_filters.push 'images' # ensure the images filter runs after all html filters text_filters.push 'images' # ensure the images filter runs after all html filters
text_filters.push 'inner_html', 'clean_text', 'attribution' text_filters.push 'inner_html', 'clean_text', 'attribution'

@ -4,10 +4,6 @@ module Docs
def call def call
@doc = at_css('#page-content') @doc = at_css('#page-content')
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
doc doc
end end
end end

@ -39,10 +39,6 @@ module Docs
node['class'] = 'col' node['class'] = 'col'
end end
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
css('figure.highlight').each do |node| css('figure.highlight').each do |node|
code = node.at_css('code') code = node.at_css('code')
node['data-language'] = code['data-lang'] node['data-language'] = code['data-lang']

@ -40,10 +40,6 @@ module Docs
node['class'] = 'col' node['class'] = 'col'
end end
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
css('.highlight').each do |node| css('.highlight').each do |node|
code = node.at_css('code') code = node.at_css('code')
node['data-language'] = code['data-lang'] node['data-language'] = code['data-lang']

@ -0,0 +1,21 @@
# frozen_string_literal: true
module Docs
class ParseCfEmailFilter < Filter
def call
css('.__cf_email__').each do |node|
str = node['data-cfemail']
mask = "0x#{str[0..1]}".hex | 0
result = ''
str.chars.drop(2).each_slice(2) do |slice|
result += "%" + "0#{("0x#{slice.join}".hex ^ mask).to_s(16)}"[-2..-1]
end
node.replace(URI.decode(result))
end
doc
end
end
end

@ -45,10 +45,6 @@ module Docs
end end
end end
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
css('.editor').each do |node| css('.editor').each do |node|
pre = node.at_css('.editor-code > pre') pre = node.at_css('.editor-code > pre')
pre['data-language'] = 'javascript' pre['data-language'] = 'javascript'

@ -8,10 +8,6 @@ module Docs
other other
end end
css('a.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
# Remove code highlighting # Remove code highlighting
css('pre').each do |node| css('pre').each do |node|
node.content = node.content node.content = node.content

@ -22,10 +22,6 @@ module Docs
node.content = node.content node.content = node.content
end end
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
doc doc
end end
end end

@ -9,10 +9,6 @@ module Docs
css('.demo', '.guide-links', '.footer', '#ad').remove css('.demo', '.guide-links', '.footer', '#ad').remove
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
# Remove code highlighting # Remove code highlighting
css('figure').each do |node| css('figure').each do |node|
node.name = 'pre' node.name = 'pre'

@ -43,10 +43,6 @@ module Docs
end end
end end
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
css('div.highlighter-rouge').each do |node| css('div.highlighter-rouge').each do |node|
node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class'] node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class']
node.content = node.content.strip node.content = node.content.strip

@ -7,7 +7,7 @@ module Docs
code: 'https://github.com/ansible/ansible' code: 'https://github.com/ansible/ansible'
} }
html_filters.push 'ansible/entries', 'ansible/clean_html', 'sphinx/clean_html' html_filters.push 'ansible/entries', 'sphinx/clean_html'
options[:skip] = %w( options[:skip] = %w(
glossary.html glossary.html

Loading…
Cancel
Save