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
6161 end
6262
6363 def include_default_entry?
64+ return false if slug.starts_with?('genindex')
6465 return true if slug == 'library/asyncio'
6566 !at_css('.body > .section:only-child > .toctree-wrapper:last-child') && !type.in?(%w(Superseded))
6667 end
6768
6869 def additional_entries
70+ return additional_entries_index if slug.starts_with?('genindex')
6971 return [] if root_page? || slug.start_with?('library/index') || !include_default_entry? || name == 'errno'
7072 clean_id_attributes
7173 entries = []
@@ -99,6 +101,28 @@ module Docs · 27 unmodified lines
99101 node.remove
100102 end
101103 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
102126 end
103127 end
104128 end
lib/docs/scrapers/python.rb+1−1
@@ -7,7 +7,7 @@ module Docs · 6 unmodified lines
77 code: 'https://github.com/python/cpython'
88 }
99
10− options[:skip_patterns] = [/genindex/, /whatsnew/]
10+ options[:skip_patterns] = [/whatsnew/]
1111 options[:skip] = %w(
1212 library/2to3.html
1313 library/formatter.html