[devdocsgjs/main: 1261/1867] PyTorch 1.6.0+ doc structure support
- From: Andy Holmes <andyholmes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devdocsgjs/main: 1261/1867] PyTorch 1.6.0+ doc structure support
- Date: Fri, 19 Nov 2021 23:47:51 +0000 (UTC)
commit cf852768ed086f24f2514712585f0d54daed8463
Author: Peiran Yao <xavieryao me com>
Date: Fri Nov 20 13:04:54 2020 -0700
PyTorch 1.6.0+ doc structure support
Document structure has changed since PyTorch 1.6.0.
lib/docs/filters/pytorch/clean_html.rb | 9 +++++++++
lib/docs/filters/pytorch/entries.rb | 18 ++++++++++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/lib/docs/filters/pytorch/clean_html.rb b/lib/docs/filters/pytorch/clean_html.rb
index dd19c3e0..465ae3a5 100644
--- a/lib/docs/filters/pytorch/clean_html.rb
+++ b/lib/docs/filters/pytorch/clean_html.rb
@@ -2,9 +2,18 @@ module Docs
class Pytorch
class CleanHtmlFilter < Filter
def call
+ breadcrumbs = at_css('.pytorch-breadcrumbs')
+ type_name = breadcrumbs.css('li')[1].content
+
@doc = at_css('.pytorch-article')
# Show katex-mathml nodes and remove katex-html nodes
css('.katex-html').remove
+
+ # pass type_name to following filters as a new node
+ node = Nokogiri::XML::Node.new 'meta', doc
+ node.content = type_name
+ doc.child.before node
+
doc
end
end
diff --git a/lib/docs/filters/pytorch/entries.rb b/lib/docs/filters/pytorch/entries.rb
index f63926b4..ba92e222 100644
--- a/lib/docs/filters/pytorch/entries.rb
+++ b/lib/docs/filters/pytorch/entries.rb
@@ -2,6 +2,15 @@ module Docs
class Pytorch
class EntriesFilter < Docs::EntriesFilter
def get_name
+ # retrive the name in breadcrumb from the auxiliary node
+ name_in_breadcrumb = doc.child.content
+ doc.child.remove
+
+ # hard-coded name replacements, for better presentation.
+ name_replacements = {
+ "Distributed communication package - torch.distributed" => "torch.distributed"
+ }
+
# The id of the container `div.section` indicates the page type.
# If the id starts with `module-`, then it's an API reference,
# otherwise it is a note or design doc.
@@ -9,7 +18,9 @@ module Docs
if doc.element_children[1]['id']&.starts_with? 'module-'
/\Amodule-(.*)/.match(doc.element_children[1]['id'])[1]
else
- at_css('h1').content
+ name_in_breadcrumb = name_in_breadcrumb.delete_suffix(' >')
+ name_in_breadcrumb = name_replacements.fetch(name_in_breadcrumb, name_in_breadcrumb)
+ name_in_breadcrumb
end
end
@@ -18,9 +29,8 @@ module Docs
end
def include_default_entry?
- # If the page is not an API reference, we only include it in the index when it
- # contains additional entries. See the doc for `get_name`.
- doc.element_children[1]['id']&.starts_with? 'module-'
+ # Only include API references, and ignore notes or design docs
+ !subpath.start_with? 'generated/' and type.start_with? 'torch'
end
def additional_entries
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]