See https://github.com/freeCodeCamp/devdocs/issues/696#issuecomment-1243554434
Unified · Split
| @@ -61,11 +61,13 @@ module Docs · 60 unmodified lines | |||
| 61 | end | 61 | 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 | end | 67 | end |
| 67 | 68 | ||
| 68 | def additional_entries | 69 | 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_attributes | 72 | clean_id_attributes |
| 71 | entries = [] | 73 | entries = [] |
| @@ -99,6 +101,28 @@ module Docs · 27 unmodified lines | |||
| 99 | node.remove | 101 | node.remove |
| 100 | end | 102 | end |
| 101 | end | 103 | 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 | end | 126 | end |
| 103 | end | 127 | end |
| 104 | end | 128 | end |
| @@ -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.html | 12 | library/2to3.html |
| 13 | library/formatter.html | 13 | library/formatter.html |