From 2e1f0a046292f6eb087fc6421e633044a8fd2331 Mon Sep 17 00:00:00 2001 From: Gergely Gombos Date: Mon, 2 Dec 2024 08:07:04 +0100 Subject: [PATCH] Address top-level page categories --- lib/docs/filters/react/entries_react_dev.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/docs/filters/react/entries_react_dev.rb b/lib/docs/filters/react/entries_react_dev.rb index 358d6a8d..69794489 100644 --- a/lib/docs/filters/react/entries_react_dev.rb +++ b/lib/docs/filters/react/entries_react_dev.rb @@ -2,17 +2,27 @@ module Docs class React class EntriesReactDevFilter < Docs::EntriesFilter def get_name - canary_copy = '- This feature is available in the latest Canary' name = at_css('article h1').content - return name.sub(canary_copy, ' (Canary)') + return update_canary_copy(name) end def get_type breadcrumb_nodes = css('a.tracking-wide') - category = breadcrumb_nodes.last.content + is_top_level_page = breadcrumb_nodes.length == 1 + category = if is_top_level_page + # Category is the opened category in the sidebar + css('aside a.text-link div').first.content + else + breadcrumb_nodes.last.content + end is_learn_page = path.start_with?('learn/') prefix = is_learn_page ? 'Learn: ' : '' - return prefix + (category || 'Miscellaneous') + return update_canary_copy(prefix + (category || 'Miscellaneous')) + end + + def update_canary_copy(string) + canary_copy = '- This feature is available in the latest Canary' + return string.sub(canary_copy, ' (Canary)') end end end