Convert the `decode_cloudflare_email` helper to a dedicated filter class

pull/775/head
Jed Fox 7 years ago committed by Thibaut Courouble
parent 68b80bce36
commit 608853bd2e

@ -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_'

@ -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', 'parse_cf_email'
options[:skip] = %w( options[:skip] = %w(
glossary.html glossary.html

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

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/facebook/flow' 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[:trailing_slash] = false
options[:root_title] = 'Flow' options[:root_title] = 'Flow'

@ -7,7 +7,7 @@ module Docs
code: 'https://github.com/laravel/laravel' 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) { options[:container] = ->(filter) {
filter.subpath.start_with?('/api') ? '#content' : '.docs-wrapper' filter.subpath.start_with?('/api') ? '#content' : '.docs-wrapper'

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/nodejs/node' 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[:title] = false
options[:root_title] = 'Node.js' options[:root_title] = 'Node.js'

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/vuejs/vue' 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[:only_patterns] = [/guide\//, /api\//]
options[:skip] = %w(guide/team.html) options[:skip] = %w(guide/team.html)

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/yarnpkg/yarn' 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[:root_title] = 'Yarn'
options[:trailing_slash] = false options[:trailing_slash] = false

Loading…
Cancel
Save