forked from freeCodeCamp/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.rb
More file actions
109 lines (82 loc) · 1.88 KB
/
filter.rb
File metadata and controls
109 lines (82 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# frozen_string_literal: true
module Docs
class Filter < ::HTML::Pipeline::Filter
def css(*args)
doc.css(*args)
end
def at_css(*args)
doc.at_css(*args)
end
def xpath(*args)
doc.xpath(*args)
end
def at_xpath(*args)
doc.at_xpath(*args)
end
def base_url
context[:base_url]
end
def links
context[:links]
end
def current_url
context[:url]
end
def root_url
context[:root_url]
end
def root_path
context[:root_path]
end
def version
context[:version]
end
def release
context[:release]
end
def subpath
@subpath ||= subpath_to(current_url)
end
def subpath_to(url)
base_url.subpath_to url, ignore_case: true
end
def slug
@slug ||= subpath.sub(/\A\//, '').remove(/\.html\z/)
end
def root_page?
subpath.blank? || subpath == '/' || subpath == root_path
end
def initial_page?
root_page? || context[:initial_paths].include?(subpath)
end
SCHEME_RGX = /\A[^:\/?#]+:/
def fragment_url_string?(str)
str[0] == '#'
end
DATA_URL = 'data:'.freeze
def data_url_string?(str)
str.start_with?(DATA_URL)
end
def relative_url_string?(str)
str !~ SCHEME_RGX && !fragment_url_string?(str) && !data_url_string?(str)
end
def absolute_url_string?(str)
str =~ SCHEME_RGX
end
def parse_html(html)
warn "#{self.class.name} is re-parsing the document" unless ENV['RACK_ENV'] == 'test'
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
end
end