Unified · Split
| @@ -2,58 +2,42 @@ module Docs · 1 unmodified line | |||
| 2 | class Relay | 2 | class Relay |
| 3 | class CleanHtmlFilter < Filter | 3 | class CleanHtmlFilter < Filter |
| 4 | def call | 4 | def call |
| 5 | @doc = at_css('.inner-content, article.withtoc') | ||
| 6 | 5 | ||
| 7 | if root_page? | 6 | if slug == 'index' |
| 8 | at_css('h1').content = 'Relay Documentation' | 7 | css('img').remove |
| 9 | end | ||
| 10 | 8 | ||
| 11 | css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide', 'hr').remove | 9 | css('.projectTitle').each do |node| |
| 10 | node.name = 'h1' | ||
| 11 | node.content = 'Relay' | ||
| 12 | end | ||
| 12 | 13 | ||
| 13 | css('table h1', 'table h2', 'table h3').each do |node| | 14 | css('pre').remove |
| 14 | table = node | ||
| 15 | table = table.parent until table.name == 'table' | ||
| 16 | table.replace(node) | ||
| 17 | end | ||
| 18 | 15 | ||
| 19 | css('a.anchor', 'a.hashref').each do |node| | ||
| 20 | node.parent['id'] ||= node['name'] || node['id'] | ||
| 21 | end | 16 | end |
| 22 | 17 | ||
| 23 | css('.highlight').each do |node| | 18 | css('.docLastUpdate').remove |
| 24 | node.name = 'pre' | ||
| 25 | node.css('.gutter').remove | ||
| 26 | node['data-language'] = node.at_css('[data-lang]').try(:[], 'data-lang') || 'js' | ||
| 27 | node.content = node.content.strip | ||
| 28 | end | ||
| 29 | 19 | ||
| 30 | css('table.highlighttable').each do |node| | 20 | css('.docs-prevnext').remove |
| 31 | node.replace(node.at_css('pre.highlight')) | ||
| 32 | end | ||
| 33 | 21 | ||
| 34 | css('.prism').each do |node| | 22 | css('.edit-page-link').remove |
| 35 | node.name = 'pre' | ||
| 36 | node['data-language'] = node['class'][/(?<=language\-)(\w+)/] | ||
| 37 | node.content = node.content | ||
| 38 | end | ||
| 39 | 23 | ||
| 40 | css('blockquote > p:first-child').each do |node| | 24 | css('h2, h3').each do |node| |
| 41 | node.remove if node.content.strip == 'Note:' | 25 | node.css('a').remove |
| 26 | node['id'] = node.content.gsub(/\s/, '-').downcase | ||
| 42 | end | 27 | end |
| 43 | 28 | ||
| 44 | css('h3#props', 'h3#methods').each { |node| node.name = 'h2' } | 29 | css('.onPageNav').remove |
| 45 | css('h4.propTitle').each { |node| node.name = 'h3' } | ||
| 46 | 30 | ||
| 47 | css('> div > div', '> div', 'div > span', '.props', '.prop').each do |node| | 31 | css('#docsNav').remove |
| 48 | node.before(node.children).remove | ||
| 49 | end | ||
| 50 | 32 | ||
| 51 | css('a pre', 'h3 .propType').each do |node| | 33 | css('.fixedHeaderContainer').remove |
| 52 | node.name = 'code' | 34 | |
| 53 | end | 35 | css('footer').remove |
| 54 | 36 | ||
| 55 | css('a[target]').each do |node| | 37 | # syntax highlight |
| 56 | node.remove_attribute('target') | 38 | css('pre').each do |node| |
| 39 | node['data-language'] = 'javascript' | ||
| 40 | node.add_class('highlight') | ||
| 57 | end | 41 | end |
| 58 | 42 | ||
| 59 | doc | 43 | doc |
| @@ -1,43 +1,53 @@ | |||
| 1 | module Docs | 1 | module Docs |
| 2 | class Relay | 2 | class Relay |
| 3 | class EntriesFilter < Docs::EntriesFilter | 3 | class EntriesFilter < Docs::EntriesFilter |
| 4 | |||
| 4 | def get_name | 5 | def get_name |
| 5 | at_css('h1').children.select(&:text?).map(&:content).join.strip | 6 | if slug == 'index' |
| 7 | return 'Relay' | ||
| 8 | end | ||
| 9 | |||
| 10 | at_css('h1').content | ||
| 6 | end | 11 | end |
| 7 | 12 | ||
| 8 | def get_type | 13 | def get_type |
| 9 | link = at_css('.nav-docs-section .active, .toc .active') | 14 | if slug == 'index' |
| 10 | section = link.ancestors('.nav-docs-section, section').first | 15 | return 'Relay' |
| 11 | type = section.at_css('h3').content.strip | 16 | end |
| 12 | type | 17 | |
| 18 | at_css('h1').content | ||
| 13 | end | 19 | end |
| 14 | 20 | ||
| 15 | def additional_entries | 21 | def additional_entries |
| 16 | entries = [] | 22 | entries = [] |
| 17 | 23 | ||
| 18 | css('.inner-content h3 code, .inner-content h4 code').each do |node| | 24 | if slug == 'index' |
| 19 | name = node.content | 25 | return entries |
| 20 | name.remove! %r{[#\(\)]} | ||
| 21 | name.remove! %r{\w+\:} | ||
| 22 | name.strip! | ||
| 23 | id = name.parameterize | ||
| 24 | node.parent['id'] = id | ||
| 25 | entries << [name, id, 'Reference'] | ||
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | css('.apiIndex a pre').each do |node| | 28 | ## avoid adding non-desired entries removing tags |
| 29 | next unless node.parent['href'].start_with?('#') | 29 | # remove header which contains a <h2> tag |
| 30 | id = node.parent['href'].remove('#') | 30 | css('.fixedHeaderContainer').remove |
| 31 | name = node.content.strip | 31 | |
| 32 | sep = name.start_with?('static') ? '.' : '#' | 32 | # remove table of content whose title is an <h2> tag |
| 33 | name.remove! %r{(abstract|static) } | 33 | css('.toc').remove |
| 34 | name.sub! %r{\(.*\)}, '()' | 34 | ## |
| 35 | name.prepend(self.name + sep) | 35 | |
| 36 | entries << [name, id] | 36 | css('h2, h3').each do |node| |
| 37 | next if node.content.include?('Argument') | ||
| 38 | entry_name = node.content | ||
| 39 | |||
| 40 | if entry_name.include?('(') | ||
| 41 | entry_name = entry_name.match(/.*\(/)[0] + ')' | ||
| 42 | end | ||
| 43 | |||
| 44 | entry_id = node.content.gsub(/\s/, '-').downcase | ||
| 45 | entries << [entry_name, entry_id] | ||
| 37 | end | 46 | end |
| 38 | 47 | ||
| 39 | entries | 48 | entries |
| 40 | end | 49 | end |
| 50 | |||
| 41 | end | 51 | end |
| 42 | end | 52 | end |
| 43 | end | 53 | end |
| @@ -1,27 +1,38 @@ | |||
| 1 | module Docs | 1 | module Docs |
| 2 | class Relay < UrlScraper | 2 | class Relay < UrlScraper |
| 3 | self.type = 'simple' | 3 | self.type = 'simple' |
| 4 | self.release = '1.4.1' | 4 | self.release = '10.1.0' |
| 5 | self.base_url = 'https://facebook.github.io/relay/docs/' | 5 | self.base_url = 'https://relay.dev' |
| 6 | self.root_path = 'getting-started.html' | 6 | self.root_path = 'index.html' |
| 7 | self.links = { | 7 | self.links = { |
| 8 | home: 'https://facebook.github.io/relay/', | 8 | home: 'https://relay.dev/', |
| 9 | code: 'https://github.com/facebook/relay' | 9 | code: 'https://github.com/facebook/relay' |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | html_filters.push 'relay/entries', 'relay/clean_html' | 12 | html_filters.push 'relay/entries', 'relay/clean_html' |
| 13 | 13 | ||
| 14 | options[:container] = '.documentationContent' | 14 | options[:only] = [ |
| 15 | options[:skip] = %w(videos.html graphql-further-reading.html) | 15 | '/docs/en/graphql-in-relay', |
| 16 | '/docs/en//relay-environment', | ||
| 17 | '/docs/en/network-layer', | ||
| 18 | '/docs/en/query-renderer', | ||
| 19 | '/docs/en/fragment-container', | ||
| 20 | '/docs/en/refetch-container', | ||
| 21 | '/docs/en/pagination-container', | ||
| 22 | '/docs/en/mutations', | ||
| 23 | '/docs/en/subscriptions', | ||
| 24 | '/docs/en/relay-store', | ||
| 25 | '/docs/en/fetch-query' | ||
| 26 | ] | ||
| 16 | 27 | ||
| 17 | options[:attribution] = <<-HTML | 28 | options[:attribution] = <<-HTML |
| 18 | © 2013–present Facebook Inc.<br> | 29 | © 2020–present Facebook Inc.<br> |
| 19 | Licensed under the BSD License. | 30 | Licensed under the BSD License. |
| 20 | HTML | 31 | HTML |
| 21 | 32 | ||
| 22 | def get_latest_version(opts) | 33 | def get_latest_version(opts) |
| 23 | doc = fetch_doc('http://facebook.github.io/relay/en/', opts) | 34 | get_latest_github_release('facebook', 'relay', opts) |
| 24 | doc.at_css('header > a > h3').content[1..-1] | ||
| 25 | end | 35 | end |
| 36 | |||
| 26 | end | 37 | end |
| 27 | end | 38 | end |