History

python: add operators, regex, symbols form index

See https://github.com/freeCodeCamp/devdocs/issues/696#issuecomment-1243554434

Simon Legner committed 4 years ago

Commit 12136291 parent 61362e62 files · +25 −1Browse files

Unified · Split

2 files
  1. lib/docs/filters/python/entries_v3.rb +24 −0
  2. lib/docs/scrapers/python.rb +1 −1
lib/docs/filters/python/entries_v3.rb+24−0
@@ -61,11 +61,13 @@ module Docs · 60 unmodified lines
61 end61 end
62 62
63 def include_default_entry?63 def include_default_entry?
64 return false if slug.starts_with?('genindex')
64 return true if slug == 'library/asyncio'65 return true if slug == 'library/asyncio'
65 !at_css('.body > .section:only-child > .toctree-wrapper:last-child') && !type.in?(%w(Superseded))66 !at_css('.body > .section:only-child > .toctree-wrapper:last-child') && !type.in?(%w(Superseded))
66 end67 end
67 68
68 def additional_entries69 def additional_entries
70 return additional_entries_index if slug.starts_with?('genindex')
69 return [] if root_page? || slug.start_with?('library/index') || !include_default_entry? || name == 'errno'71 return [] if root_page? || slug.start_with?('library/index') || !include_default_entry? || name == 'errno'
70 clean_id_attributes72 clean_id_attributes
71 entries = []73 entries = []
@@ -99,6 +101,28 @@ module Docs · 27 unmodified lines
99 node.remove101 node.remove
100 end102 end
101 end103 end
104
105 def additional_entries_index
106 css('.genindextable td > ul > li').each_with_object [] do |node, entries|
107 name = node.children.first
108 next unless name.text?
109 name = name.text.strip()
110 next if name[/^\w/] || name[/^-+\w/]
111 node.css('> ul > li > a').each do |inner_node|
112 inner_name = inner_node.text.strip()
113 next if inner_name[/\[\d+\]/]
114 type = case inner_name
115 when 'operator'
116 'Operators'
117 when 'in regular expressions'
118 'Regular Expression'
119 else
120 'Symbols'
121 end
122 entries << ["#{name} (#{inner_name})", inner_node['href'], type]
123 end
124 end
125 end
102 end126 end
103 end127 end
104end128end
lib/docs/scrapers/python.rb+1−1
@@ -7,7 +7,7 @@ module Docs · 6 unmodified lines
7 code: 'https://github.com/python/cpython'7 code: 'https://github.com/python/cpython'
8 }8 }
9 9
10 options[:skip_patterns] = [/genindex/, /whatsnew/]10 options[:skip_patterns] = [/whatsnew/]
11 options[:skip] = %w(11 options[:skip] = %w(
12 library/2to3.html12 library/2to3.html
13 library/formatter.html13 library/formatter.html