1
0
Эх сурвалжийг харах

Address top-level page categories

Gergely Gombos 1 жил өмнө
parent
commit
2e1f0a0462

+ 14 - 4
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