Skip to content

Commit

Permalink
Improve React docs
Browse files Browse the repository at this point in the history
  • Loading branch information
j-f1 committed Jan 30, 2020
1 parent e2acab1 commit 038869a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/docs/filters/react/clean_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def call
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

Expand All @@ -24,6 +24,11 @@ def call
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
Expand Down
22 changes: 17 additions & 5 deletions lib/docs/filters/react/entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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*\(.*\)}
type
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+\:}
Expand All @@ -29,10 +37,14 @@ def additional_entries
'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
Expand Down

0 comments on commit 038869a

Please sign in to comment.