use better top-level categories

pull/2375/head
Gergely Gombos 1 month ago
parent 7a510f6d8b
commit 94a7aa3c34

@ -31,9 +31,7 @@ module Docs
end end
# Remove styling divs while lifting children # Remove styling divs while lifting children
styling_prefixes = [ styling_prefixes = %w[ps- mx- my- px- py- mb- sp- rounded-]
'ps-', 'mx-', 'my-', 'px-', 'py-', 'mb-', 'sp-', 'rounded-'
]
selectors = styling_prefixes.map { |prefix| "div[class*=\"#{prefix}\"]" } selectors = styling_prefixes.map { |prefix| "div[class*=\"#{prefix}\"]" }
css(*selectors, 'div[class=""]', 'div.cm-line').each do |node| css(*selectors, 'div[class=""]', 'div.cm-line').each do |node|
node.before(node.children).remove node.before(node.children).remove

@ -2,21 +2,21 @@ module Docs
class React class React
class EntriesReactDevFilter < Docs::EntriesFilter class EntriesReactDevFilter < Docs::EntriesFilter
def get_name def get_name
name = at_css('article h1').content name = at_css('article h1')&.content
return update_canary_copy(name) return update_canary_copy(name)
end end
def get_type def get_type
breadcrumb_nodes = css('a.tracking-wide') # Category is the opened category in the sidebar
is_top_level_page = breadcrumb_nodes.length == 1 category = css('a:has(> span.text-link) > div').first&.content
category = if is_top_level_page # The grey category in the sidebar
# Category is the opened category in the sidebar top_category = css('h3:has(~ li a.text-link)')
css('aside a.text-link div').first.content .last&.content
else &.sub(/@.*$/, '') # remove version tag
breadcrumb_nodes.last.content &.sub(/^./, &:upcase) # capitalize first letter
end &.concat(": ")
is_learn_page = path.start_with?('learn/') is_learn_page = path.start_with?('learn/') || slug == 'learn'
prefix = is_learn_page ? 'Learn: ' : '' prefix = is_learn_page ? 'Learn: ' : top_category
return update_canary_copy(prefix + (category || 'Miscellaneous')) return update_canary_copy(prefix + (category || 'Miscellaneous'))
end end

Loading…
Cancel
Save