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'
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
end
@ -24,6 +24,11 @@ module Docs
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('[class*="css-"]').each do |node|
node['class'] = node['class'].sub(/css-[^ ]+(\b|$)/, '')
node.delete 'class' if node['class'] == ''
end
doc
end
end

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

Loading…
Cancel
Save