Convert the `decode_cloudflare_email` helper to a dedicated filter class

pull/721/head
Jed Fox 7 years ago
parent ee0f02a214
commit 8587239211

@ -91,17 +91,6 @@ module Docs
super
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)
path.gsub %r{[!;:]+}, '-'
end

@ -1,13 +0,0 @@
module Docs
class Ansible
class CleanHtmlFilter < Filter
def call
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
doc
end
end
end
end

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

@ -38,10 +38,6 @@ module Docs
node['class'] = 'col'
end
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
css('.highlight').each do |node|
code = node.at_css('code')
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
css('.__cf_email__').each do |node|
node.replace(decode_cloudflare_email(node['data-cfemail']))
end
css('.editor').each do |node|
pre = node.at_css('.editor-code > pre')
pre['data-language'] = 'javascript'

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

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

@ -9,10 +9,6 @@ module Docs
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
css('figure').each do |node|
node.name = 'pre'

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

@ -9,7 +9,7 @@ module Docs
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', 'parse_cf_email'
options[:container] = '#page-content'

@ -15,6 +15,8 @@ module Docs
Documentation licensed under the Creative Commons Attribution License v3.0.
HTML
html_filters.push 'parse_cf_email'
version '4' do
self.release = '4.0.0-beta'
self.base_url = 'https://getbootstrap.com/docs/4.0/'

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/facebook/flow'
}
html_filters.push 'flow/entries', 'flow/clean_html', 'title'
html_filters.push 'flow/entries', 'flow/clean_html', 'title', 'parse_cf_email'
options[:trailing_slash] = false
options[:root_title] = 'Flow'

@ -7,7 +7,7 @@ module Docs
code: 'https://github.com/laravel/laravel'
}
html_filters.push 'laravel/entries', 'laravel/clean_html'
html_filters.push 'laravel/entries', 'laravel/clean_html', 'parse_cf_email'
options[:container] = ->(filter) {
filter.subpath.start_with?('/api') ? '#content' : '.docs-wrapper'

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/nodejs/node'
}
html_filters.push 'node/clean_html', 'node/entries', 'title'
html_filters.push 'node/clean_html', 'node/entries', 'title', 'parse_cf_email'
options[:title] = false
options[:root_title] = 'Node.js'

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/vuejs/vue'
}
html_filters.push 'vue/entries', 'vue/clean_html'
html_filters.push 'vue/entries', 'vue/clean_html', 'parse_cf_email'
options[:only_patterns] = [/guide\//, /api\//]
options[:skip] = %w(guide/team.html)

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/yarnpkg/yarn'
}
html_filters.push 'yarn/entries', 'yarn/clean_html', 'title'
html_filters.push 'yarn/entries', 'yarn/clean_html', 'title', 'parse_cf_email'
options[:root_title] = 'Yarn'
options[:trailing_slash] = false

Loading…
Cancel
Save