From 6e419996c57dd8ceeff1bb1ad8ddd28fb0e29af2 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sun, 2 Oct 2022 10:55:11 +0200 Subject: [PATCH 1/4] python: include h2 entries for library docs See #696. --- lib/docs/filters/python/entries_v3.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/docs/filters/python/entries_v3.rb b/lib/docs/filters/python/entries_v3.rb index 033427f4..fd3f5945 100644 --- a/lib/docs/filters/python/entries_v3.rb +++ b/lib/docs/filters/python/entries_v3.rb @@ -57,7 +57,7 @@ module Docs end def include_h2? - return slug.start_with?('reference') || slug.start_with?('tutorial') || slug.start_with?('using') + return slug.start_with?('library') || slug.start_with?('reference') || slug.start_with?('tutorial') || slug.start_with?('using') end def include_default_entry? @@ -81,6 +81,7 @@ module Docs if include_h2? css('section[id] > h2').each do |node| name = node.content.remove("\u{00b6}") + name.concat " (#{self.name})" if slug.start_with?('library') entries << [name, node.parent['id']] end end From 61362e6e6efe50a0a35695c13c7261327fcfdb75 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sun, 2 Oct 2022 11:34:33 +0200 Subject: [PATCH 2/4] python: add statement entries See https://github.com/freeCodeCamp/devdocs/issues/696#issuecomment-1239665712 --- lib/docs/filters/python/entries_v3.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/docs/filters/python/entries_v3.rb b/lib/docs/filters/python/entries_v3.rb index fd3f5945..fe474650 100644 --- a/lib/docs/filters/python/entries_v3.rb +++ b/lib/docs/filters/python/entries_v3.rb @@ -83,6 +83,8 @@ module Docs name = node.content.remove("\u{00b6}") name.concat " (#{self.name})" if slug.start_with?('library') entries << [name, node.parent['id']] + statement = name[/The (.+) statement/, 1] + entries << ["#{statement} (statement)", node.parent['id'], 'Statements'] if statement && slug.start_with?('reference') end end From 1213629e9cd50434d195542a027e85ad1cd3d79a Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sun, 2 Oct 2022 12:34:22 +0200 Subject: [PATCH 3/4] python: add operators, regex, symbols form index See https://github.com/freeCodeCamp/devdocs/issues/696#issuecomment-1243554434 --- lib/docs/filters/python/entries_v3.rb | 24 ++++++++++++++++++++++++ lib/docs/scrapers/python.rb | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/docs/filters/python/entries_v3.rb b/lib/docs/filters/python/entries_v3.rb index fe474650..e7fcb4fd 100644 --- a/lib/docs/filters/python/entries_v3.rb +++ b/lib/docs/filters/python/entries_v3.rb @@ -61,11 +61,13 @@ module Docs end def include_default_entry? + return false if slug.starts_with?('genindex') return true if slug == 'library/asyncio' !at_css('.body > .section:only-child > .toctree-wrapper:last-child') && !type.in?(%w(Superseded)) end def additional_entries + return additional_entries_index if slug.starts_with?('genindex') return [] if root_page? || slug.start_with?('library/index') || !include_default_entry? || name == 'errno' clean_id_attributes entries = [] @@ -99,6 +101,28 @@ module Docs node.remove end end + + def additional_entries_index + css('.genindextable td > ul > li').each_with_object [] do |node, entries| + name = node.children.first + next unless name.text? + name = name.text.strip() + next if name[/^\w/] || name[/^-+\w/] + node.css('> ul > li > a').each do |inner_node| + inner_name = inner_node.text.strip() + next if inner_name[/\[\d+\]/] + type = case inner_name + when 'operator' + 'Operators' + when 'in regular expressions' + 'Regular Expression' + else + 'Symbols' + end + entries << ["#{name} (#{inner_name})", inner_node['href'], type] + end + end + end end end end diff --git a/lib/docs/scrapers/python.rb b/lib/docs/scrapers/python.rb index 6f3c6f1e..09d84204 100644 --- a/lib/docs/scrapers/python.rb +++ b/lib/docs/scrapers/python.rb @@ -7,7 +7,7 @@ module Docs code: 'https://github.com/python/cpython' } - options[:skip_patterns] = [/genindex/, /whatsnew/] + options[:skip_patterns] = [/whatsnew/] options[:skip] = %w( library/2to3.html library/formatter.html From 1de7a61a97f005ef0283d1052746a4aa61389a9c Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sun, 2 Oct 2022 12:39:56 +0200 Subject: [PATCH 4/4] python: add glossary entries --- lib/docs/filters/python/entries_v3.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/docs/filters/python/entries_v3.rb b/lib/docs/filters/python/entries_v3.rb index e7fcb4fd..90c9a970 100644 --- a/lib/docs/filters/python/entries_v3.rb +++ b/lib/docs/filters/python/entries_v3.rb @@ -31,6 +31,7 @@ module Docs return 'Tutorial' if slug.start_with? 'tutorial' return 'Software Packaging & Distribution' if slug.start_with? 'distributing' return 'Software Packaging & Distribution' if slug.start_with? 'distutils' + return 'Glossary' if slug.start_with? 'glossary' return 'Basics' unless slug.start_with? 'library/' return 'Basics' if slug.start_with? 'library/index' @@ -76,6 +77,10 @@ module Docs entries << [node['id'], node['id']] end + css('.glossary > dt[id]').each do |node| + entries << [node.content, node['id']] + end + css('.function > dt[id]', '.method > dt[id]', '.staticmethod > dt[id]', '.classmethod > dt[id]').each do |node| entries << [node['id'] + '()', node['id']] end