Support PyTorch v1.6.0+ doc structure
Unified · Split
| @@ -1,15 +1,23 @@ | ||
| 1 | 1 | module Docs |
| 2 | 2 | class Pytorch |
| 3 | 3 | class EntriesFilter < Docs::EntriesFilter |
| 4 | + NAME_REPLACEMENTS = { | |
| 5 | + "Distributed communication package - torch.distributed" => "torch.distributed" | |
| 6 | + } | |
| 7 | + | |
| 8 | + def get_breadcrumbs() | |
| 9 | + css('.pytorch-breadcrumbs > li').map { |node| node.content.delete_suffix(' >') } | |
| 10 | + end | |
| 11 | + | |
| 4 | 12 | def get_name |
| 5 | 13 | # The id of the container `div.section` indicates the page type. |
| 6 | 14 | # If the id starts with `module-`, then it's an API reference, |
| 7 | 15 | # otherwise it is a note or design doc. |
| 8 | − # After the `sphinx/clean_html` filter, that id is assigned to the second element. | |
| 9 | − if doc.element_children[1]['id']&.starts_with? 'module-' | |
| 10 | − /\Amodule-(.*)/.match(doc.element_children[1]['id'])[1] | |
| 16 | + if at_css('.section')['id'].starts_with? 'module-' | |
| 17 | + /\Amodule-(.*)/.match(article_id)[1] | |
| 11 | 18 | else |
| 12 | − at_css('h1').content | |
| 19 | + name = get_breadcrumbs()[1] | |
| 20 | + NAME_REPLACEMENTS.fetch(name, name) | |
| 13 | 21 | end |
| 14 | 22 | end |
| 15 | 23 | |
| @@ -18,9 +26,8 @@ module Docs · 2 unmodified lines | ||
| 18 | 26 | end |
| 19 | 27 | |
| 20 | 28 | def include_default_entry? |
| 21 | − # If the page is not an API reference, we only include it in the index when it | |
| 22 | − # contains additional entries. See the doc for `get_name`. | |
| 23 | − doc.element_children[1]['id']&.starts_with? 'module-' | |
| 29 | + # Only include API references, and ignore notes or design docs | |
| 30 | + !subpath.start_with? 'generated/' and type.start_with? 'torch' | |
| 24 | 31 | end |
| 25 | 32 | |
| 26 | 33 | def additional_entries |
| @@ -9,7 +9,7 @@ module Docs · 8 unmodified lines | ||
| 9 | 9 | code: 'https://github.com/pytorch/pytorch' |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | − html_filters.push 'pytorch/clean_html', 'sphinx/clean_html', 'pytorch/entries' | |
| 12 | + html_filters.push 'pytorch/entries', 'pytorch/clean_html', 'sphinx/clean_html' | |
| 13 | 13 | |
| 14 | 14 | options[:skip] = ['cpp_index.html', 'packages.html', 'py-modindex.html', 'genindex.html'] |
| 15 | 15 | options[:skip_patterns] = [/\Acommunity/, /\A_modules/, /\Anotes/, /\Aorg\/pytorch\//] |