Skip to content

Commit fefde4e

Browse files
committed
add Learn pages
1 parent df398bd commit fefde4e

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

lib/docs/filters/react/clean_html_react_dev.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ def call
66

77
# Remove breadcrumbs before h1
88
css('h1').each do |node|
9-
node.previous.remove
9+
if (node.previous)
10+
node.previous.remove
11+
end
1012
end
1113

1214
remove_selectors = [

lib/docs/filters/react/entries_react_dev.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ class EntriesReactDevFilter < Docs::EntriesFilter
44
def get_name
55
canary_copy = '- This feature is available in the latest Canary'
66
name = at_css('article h1').content
7-
return name.sub(canary_copy, ' (Experimental)')
7+
return name.sub(canary_copy, ' (Canary)')
88
end
99

1010
def get_type
1111
breadcrumb_nodes = css('a.tracking-wide')
12-
return breadcrumb_nodes.last.content || 'Miscellaneous'
12+
category = breadcrumb_nodes.last.content
13+
is_learn_page = base_url.to_s.end_with?('learn')
14+
prefix = is_learn_page ? 'Learn: ' : ''
15+
return prefix + (category || 'Miscellaneous')
1316
end
1417
end
1518
end

lib/docs/scrapers/react.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module Docs
22
class React < UrlScraper
3+
include MultipleBaseUrls
4+
35
self.name = 'React'
46
self.type = 'simple'
57
self.links = {
@@ -9,8 +11,12 @@ class React < UrlScraper
911

1012
version do
1113
self.release = '18.3.1'
12-
# TODO add /learn
13-
self.base_url = 'https://react.dev/reference'
14+
host = 'https://react.dev'
15+
self.base_urls = [
16+
"#{host}/reference",
17+
"#{host}/learn",
18+
]
19+
self.initial_paths = %w(/react)
1420

1521
html_filters.push 'react/entries_react_dev', 'react/clean_html_react_dev'
1622

0 commit comments

Comments
 (0)