History

Update Relay to 10.1.0

MasterEnoc committed 5 years ago

Commit e9322e41 parent a525a793 files · +74 −69Browse files

Unified · Split

3 files
  1. lib/docs/filters/relay/clean_html.rb +22 −38
  2. lib/docs/filters/relay/entries.rb +32 −22
  3. lib/docs/scrapers/relay.rb +20 −9
lib/docs/filters/relay/clean_html.rb+22−38
@@ -2,58 +2,42 @@ module Docs · 1 unmodified line
22 class Relay
33 class CleanHtmlFilter < Filter
44 def call
5− @doc = at_css('.inner-content, article.withtoc')
65
7− if root_page?
8− at_css('h1').content = 'Relay Documentation'
9− end
6+ if slug == 'index'
7+ css('img').remove
108
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
1213
13− css('table h1', 'table h2', 'table h3').each do |node|
14− table = node
15− table = table.parent until table.name == 'table'
16− table.replace(node)
17− end
14+ css('pre').remove
1815
19− css('a.anchor', 'a.hashref').each do |node|
20− node.parent['id'] ||= node['name'] || node['id']
2116 end
2217
23− css('.highlight').each do |node|
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
18+ css('.docLastUpdate').remove
2919
30− css('table.highlighttable').each do |node|
31− node.replace(node.at_css('pre.highlight'))
32− end
20+ css('.docs-prevnext').remove
3321
34− css('.prism').each do |node|
35− node.name = 'pre'
36− node['data-language'] = node['class'][/(?<=language\-)(\w+)/]
37− node.content = node.content
38− end
22+ css('.edit-page-link').remove
3923
40− css('blockquote > p:first-child').each do |node|
41− node.remove if node.content.strip == 'Note:'
24+ css('h2, h3').each do |node|
25+ node.css('a').remove
26+ node['id'] = node.content.gsub(/\s/, '-').downcase
4227 end
4328
44− css('h3#props', 'h3#methods').each { |node| node.name = 'h2' }
45− css('h4.propTitle').each { |node| node.name = 'h3' }
29+ css('.onPageNav').remove
4630
47− css('> div > div', '> div', 'div > span', '.props', '.prop').each do |node|
48− node.before(node.children).remove
49− end
31+ css('#docsNav').remove
5032
51− css('a pre', 'h3 .propType').each do |node|
52− node.name = 'code'
53− end
33+ css('.fixedHeaderContainer').remove
34+
35+ css('footer').remove
5436
55− css('a[target]').each do |node|
56− node.remove_attribute('target')
37+ # syntax highlight
38+ css('pre').each do |node|
39+ node['data-language'] = 'javascript'
40+ node.add_class('highlight')
5741 end
5842
5943 doc
lib/docs/filters/relay/entries.rb+32−22
@@ -1,43 +1,53 @@
11 module Docs
22 class Relay
33 class EntriesFilter < Docs::EntriesFilter
4+
45 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
611 end
712
813 def get_type
9− link = at_css('.nav-docs-section .active, .toc .active')
10− section = link.ancestors('.nav-docs-section, section').first
11− type = section.at_css('h3').content.strip
12− type
14+ if slug == 'index'
15+ return 'Relay'
16+ end
17+
18+ at_css('h1').content
1319 end
1420
1521 def additional_entries
1622 entries = []
1723
18− css('.inner-content h3 code, .inner-content h4 code').each do |node|
19− name = node.content
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']
24+ if slug == 'index'
25+ return entries
2626 end
2727
28− css('.apiIndex a pre').each do |node|
29− next unless node.parent['href'].start_with?('#')
30− id = node.parent['href'].remove('#')
31− name = node.content.strip
32− sep = name.start_with?('static') ? '.' : '#'
33− name.remove! %r{(abstract|static) }
34− name.sub! %r{\(.*\)}, '()'
35− name.prepend(self.name + sep)
36− entries << [name, id]
28+ ## avoid adding non-desired entries removing tags
29+ # remove header which contains a <h2> tag
30+ css('.fixedHeaderContainer').remove
31+
32+ # remove table of content whose title is an <h2> tag
33+ css('.toc').remove
34+ ##
35+
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]
3746 end
3847
3948 entries
4049 end
50+
4151 end
4252 end
4353 end
lib/docs/scrapers/relay.rb+20−9
@@ -1,27 +1,38 @@
11 module Docs
22 class Relay < UrlScraper
33 self.type = 'simple'
4− self.release = '1.4.1'
5− self.base_url = 'https://facebook.github.io/relay/docs/'
6− self.root_path = 'getting-started.html'
4+ self.release = '10.1.0'
5+ self.base_url = 'https://relay.dev'
6+ self.root_path = 'index.html'
77 self.links = {
8− home: 'https://facebook.github.io/relay/',
8+ home: 'https://relay.dev/',
99 code: 'https://github.com/facebook/relay'
1010 }
1111
1212 html_filters.push 'relay/entries', 'relay/clean_html'
1313
14− options[:container] = '.documentationContent'
15− options[:skip] = %w(videos.html graphql-further-reading.html)
14+ options[:only] = [
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+ ]
1627
1728 options[:attribution] = <<-HTML
18− &copy; 2013&ndash;present Facebook Inc.<br>
29+ &copy; 2020&ndash;present Facebook Inc.<br>
1930 Licensed under the BSD License.
2031 HTML
2132
2233 def get_latest_version(opts)
23− doc = fetch_doc('http://facebook.github.io/relay/en/', opts)
24− doc.at_css('header > a > h3').content[1..-1]
34+ get_latest_github_release('facebook', 'relay', opts)
2535 end
36+
2637 end
2738 end