Skip to content

Commit 94a7aa3

Browse files
committed
use better top-level categories
1 parent 7a510f6 commit 94a7aa3

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

lib/docs/filters/react/clean_html_react_dev.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def call
3131
end
3232

3333
# Remove styling divs while lifting children
34-
styling_prefixes = [
35-
'ps-', 'mx-', 'my-', 'px-', 'py-', 'mb-', 'sp-', 'rounded-'
36-
]
34+
styling_prefixes = %w[ps- mx- my- px- py- mb- sp- rounded-]
3735
selectors = styling_prefixes.map { |prefix| "div[class*=\"#{prefix}\"]" }
3836
css(*selectors, 'div[class=""]', 'div.cm-line').each do |node|
3937
node.before(node.children).remove

lib/docs/filters/react/entries_react_dev.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ module Docs
22
class React
33
class EntriesReactDevFilter < Docs::EntriesFilter
44
def get_name
5-
name = at_css('article h1').content
5+
name = at_css('article h1')&.content
66
return update_canary_copy(name)
77
end
88

99
def get_type
10-
breadcrumb_nodes = css('a.tracking-wide')
11-
is_top_level_page = breadcrumb_nodes.length == 1
12-
category = if is_top_level_page
13-
# Category is the opened category in the sidebar
14-
css('aside a.text-link div').first.content
15-
else
16-
breadcrumb_nodes.last.content
17-
end
18-
is_learn_page = path.start_with?('learn/')
19-
prefix = is_learn_page ? 'Learn: ' : ''
10+
# Category is the opened category in the sidebar
11+
category = css('a:has(> span.text-link) > div').first&.content
12+
# The grey category in the sidebar
13+
top_category = css('h3:has(~ li a.text-link)')
14+
.last&.content
15+
&.sub(/@.*$/, '') # remove version tag
16+
&.sub(/^./, &:upcase) # capitalize first letter
17+
&.concat(": ")
18+
is_learn_page = path.start_with?('learn/') || slug == 'learn'
19+
prefix = is_learn_page ? 'Learn: ' : top_category
2020
return update_canary_copy(prefix + (category || 'Miscellaneous'))
2121
end
2222

0 commit comments

Comments
 (0)