@@ -2,95 +2,40 @@ module Docs
22 class Http
33 class EntriesFilter < Docs ::EntriesFilter
44 def get_name
5- name = at_css ( 'h1' ) . content
6- name . remove! %r{\A .+\: }
7- name . remove! %r{\A .+\- \- }
8- "#{ rfc } : #{ name . strip } "
5+ if current_url . host == 'tools.ietf.org'
6+ name = at_css ( 'h1' ) . content
7+ name . remove! %r{\A .+\: }
8+ name . remove! %r{\A .+\- \- }
9+ rfc = slug . sub ( 'rfc' , 'RFC ' )
10+ "#{ rfc } : #{ name . strip } "
11+ elsif slug . start_with? ( 'Status' )
12+ at_css ( 'code' ) . content
13+ else
14+ name = super
15+ name . remove! %r{\A \w +\. }
16+ name . remove! 'Basics of HTTP.'
17+ name . sub! 'Content-Security-Policy.' , 'CSP.'
18+ name . sub! '.' , ': '
19+ name . sub! '1: x' , '1.x'
20+ name
21+ end
922 end
1023
1124 def get_type
12- 'RFC'
13- end
14-
15- def rfc
16- slug . sub ( 'rfc' , 'RFC ' )
17- end
18-
19- SECTIONS = {
20- 'rfc2616' => [
21- [ 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 15 ] ,
22- [ 14 ] ,
23- [ ]
24- ] ,
25- 'rfc4918' => [
26- [ ] ,
27- [ 11 ] ,
28- [ ]
29- ] ,
30- 'rfc7230' => [
31- ( 2 ..9 ) . to_a ,
32- [ ] ,
33- [ ]
34- ] ,
35- 'rfc7231' => [
36- [ 3 , 8 , 9 ] ,
37- [ ] ,
38- [ 4 , 5 , 6 , 7 ]
39- ] ,
40- 'rfc7232' => [
41- [ 5 , 6 , 7 , 8 ] ,
42- [ 2 , 3 , 4 ] ,
43- [ ]
44- ] ,
45- 'rfc7233' => [
46- [ 5 , 6 ] ,
47- [ 2 , 3 , 4 ] ,
48- [ ]
49- ] ,
50- 'rfc7234' => [
51- [ 3 , 6 , 7 , 8 ] ,
52- [ 4 , 5 ] ,
53- [ ]
54- ] ,
55- 'rfc7235' => [
56- [ 2 , 5 , 6 ] ,
57- [ 3 , 4 ] ,
58- [ ]
59- ]
60- }
61-
62- LEVEL_1 = /\A (\d +)\z /
63- LEVEL_2 = /\A (\d +)\. \d +\z /
64- LEVEL_3 = /\A (\d +)\. \d +\. \d +\z /
65-
66- def additional_entries
67- return [ ] if root_page?
68- type = nil
69-
70- css ( 'a[href^="#section-"]' ) . each_with_object ( [ ] ) do |node , entries |
71- id = node [ 'href' ] . remove ( '#' )
72- break entries if entries . any? { |e | e [ 1 ] == id }
73-
74- content = node . next . content . strip
75- content . remove! %r{\s *\. +\d *\z }
76- content . remove! %r{\A [\. \s ]+}
77-
78- name = "#{ content } (#{ rfc } )"
79- number = node . content . strip
80-
81- if number =~ LEVEL_1
82- if SECTIONS [ slug ] [ 0 ] . include? ( $1. to_i )
83- entries << [ name , id , self . name ]
84- end
85-
86- type = content . sub ( /\ Definitions\z / , 's' )
87- type = 'Request Header Fields' if type . include? ( 'Header Fields' ) && type . exclude? ( 'Response' )
88- type = 'Response Status Codes' if type . include? ( 'Status Codes' )
89- type = self . name unless type . start_with? ( 'Request ' ) || type . start_with? ( 'Response ' )
90- elsif ( number =~ LEVEL_2 && SECTIONS [ slug ] [ 1 ] . include? ( $1. to_i ) ) ||
91- ( number =~ LEVEL_3 && SECTIONS [ slug ] [ 2 ] . include? ( $1. to_i ) )
92- entries << [ name , id , ( name =~ /\A \d \d \d / ? 'Response Status Codes' : type ) ]
93- end
25+ return 'RFC' if current_url . host == 'tools.ietf.org'
26+
27+ if slug . start_with? ( 'Headers/Content-Security-Policy' )
28+ 'CSP'
29+ elsif slug . start_with? ( 'Headers' )
30+ 'Headers'
31+ elsif slug . start_with? ( 'Methods' )
32+ 'Methods'
33+ elsif slug . start_with? ( 'Status' )
34+ 'Status'
35+ elsif slug . start_with? ( 'Basics_of_HTTP' )
36+ 'Guides: Basics'
37+ else
38+ 'Guides'
9439 end
9540 end
9641 end
0 commit comments