Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/docs/filters/pytorch/clean_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ module Docs
class Pytorch
class CleanHtmlFilter < Filter
def call
@doc = at_css('.pytorch-article')
# Show katex-mathml nodes and remove katex-html nodes
css('.katex-html').remove
if root = at_css('#pytorch-article')
@doc = root
# Show katex-mathml nodes and remove katex-html nodes
css('.katex-html').remove
end
doc
end
end
Expand Down
30 changes: 26 additions & 4 deletions lib/docs/filters/pytorch/entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,39 @@ module Docs
class Pytorch
class EntriesFilter < Docs::EntriesFilter
def get_breadcrumbs
css('.pytorch-breadcrumbs > li').map {
|node| node.content.delete_suffix(' >').strip
}.reject { |item| item.nil? || item.empty? }
breadcrumbs = if at_css('.pytorch-breadcrumbs')
css('.pytorch-breadcrumbs > li').map { |node|
node.content.delete_suffix(' >').strip
}
else
css('.bd-breadcrumbs > li').map { |node|
text = node.content.strip
text.empty? && node.at_css('.fa-home') ? 'Docs' : text
}
end.reject { |item| item.nil? || item.empty? }

if breadcrumbs.last&.end_with?('.')
resolved_name = at_css('h1').content.delete_suffix('#').strip
breadcrumbs[-1] = resolved_name
end

breadcrumbs
end

def get_name
get_breadcrumbs[-1]
end

def get_type
get_breadcrumbs[1]
if at_css('.pytorch-breadcrumbs')
get_breadcrumbs[1]
else
get_breadcrumbs.size > 2 ? get_breadcrumbs[2] : get_breadcrumbs[1]
end
end

def include_default_entry?
!get_breadcrumbs.nil? && get_breadcrumbs.size >= 2
end

def additional_entries
Expand Down
10 changes: 10 additions & 0 deletions lib/docs/scrapers/pytorch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class Pytorch < UrlScraper
PyTorch has a BSD-style license, as found in the <a href="https://github.com/pytorch/pytorch/blob/main/LICENSE">LICENSE</a> file.
HTML

version '2.9' do
self.release = '2.9'
self.base_url = "https://docs.pytorch.org/docs/#{release}/"
end

version '2.8' do
self.release = '2.8'
self.base_url = "https://docs.pytorch.org/docs/#{release}/"
end

version '2.7' do
self.release = '2.7'
self.base_url = "https://docs.pytorch.org/docs/#{release}/"
Expand Down