| @@ -2,21 +2,21 @@ module Docs · 1 unmodified line |
| 2 | 2 | class React |
| 3 | 3 | class EntriesReactDevFilter < Docs::EntriesFilter |
| 4 | 4 | def get_name |
| 5 | | − name = at_css('article h1').content |
| 5 | + name = at_css('article h1')&.content |
| 6 | 6 | return update_canary_copy(name) |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | 9 | 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 |
| 20 | 20 | return update_canary_copy(prefix + (category || 'Miscellaneous')) |
| 21 | 21 | end |
| 22 | 22 | |