Improve React docs

pull/1173/head
Jed Fox 5 years ago
parent e2acab1d91
commit 038869aa67

@ -8,7 +8,7 @@ module Docs
at_css('h1').content = 'React Documentation' at_css('h1').content = 'React Documentation'
end end
css('header', 'div[class^="css-"]', '.gatsby-resp-image-link span').each do |node| css('header', 'div[class^="css-"]', '.gatsby-resp-image-link span', 'div.scary').each do |node|
node.before(node.children).remove node.before(node.children).remove
end end
@ -24,6 +24,11 @@ module Docs
css('a').remove_attr('rel').remove_attr('target').remove_attr('class').remove_attr('style') css('a').remove_attr('rel').remove_attr('target').remove_attr('class').remove_attr('style')
css('img').remove_attr('style').remove_attr('srcset').remove_attr('sizes').remove_attr('class') css('img').remove_attr('style').remove_attr('srcset').remove_attr('sizes').remove_attr('class')
css('[class*="css-"]').each do |node|
node['class'] = node['class'].sub(/css-[^ ]+(\b|$)/, '')
node.delete 'class' if node['class'] == ''
end
doc doc
end end
end end

@ -2,22 +2,30 @@ module Docs
class React class React
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
at_css('article h1').content at_css('article h1').content.sub(' (Experimental)', '')
end end
def get_type def get_type
return 'API Reference' if slug == 'legacy-context'
return 'Glossary' if slug == 'glossary'
link = css("nav a[href='#{result[:path].split('/').last}']").last link = css("nav a[href='#{result[:path].split('/').last}']").last
return 'Miscellaneous' unless link return 'Miscellaneous' unless link
type = link.ancestors('ul').last.previous_element.content type = link.ancestors('ul').last.previous_element.content
type.remove! %r{\s*\(.*\)} type.remove! %r{\s*\(.*\)}
if type == 'Concurrent Mode'
type + ' (Experimental)' # TODO: Remove when CM is stable
else
type type
end end
end
def additional_entries def additional_entries
entries = [] entries = []
css('article h3 code, article h4 code').each do |node| is_glossary = slug == 'glossary'
next if node.previous.try(:content).present? css(is_glossary ? 'article h2, article h3' : 'article h3 code, article h4 code').each do |node|
next if !is_glossary && node.previous.try(:content).present?
next if slug == 'testing-recipes'
name = node.content.strip name = node.content.strip
# name.remove! %r{[#\(\)]} # name.remove! %r{[#\(\)]}
# name.remove! %r{\w+\:} # name.remove! %r{\w+\:}
@ -29,10 +37,14 @@ module Docs
'Reference: React' 'Reference: React'
elsif slug == 'hooks-reference' elsif slug == 'hooks-reference'
'Hooks' 'Hooks'
elsif slug == 'test-utils'
'Reference: Test Utilities'
elsif slug == 'glossary'
'Glossary'
else else
'Reference' 'Reference'
end end
entries << [name, node.parent['id'], type] entries << [name, node['id'] || node.ancestors('[id]').first['id'], type]
end end
entries entries

Loading…
Cancel
Save