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