Răsfoiți Sursa

add Learn pages

Gergely Gombos 1 an în urmă
părinte
comite
fefde4e15b

+ 3 - 1
lib/docs/filters/react/clean_html_react_dev.rb

@@ -6,7 +6,9 @@ module Docs
 
         # Remove breadcrumbs before h1
         css('h1').each do |node|
-          node.previous.remove
+          if (node.previous)
+            node.previous.remove
+          end
         end
 
         remove_selectors = [

+ 5 - 2
lib/docs/filters/react/entries_react_dev.rb

@@ -4,12 +4,15 @@ module Docs
       def get_name
         canary_copy = '- This feature is available in the latest Canary'
         name = at_css('article h1').content
-        return name.sub(canary_copy, ' (Experimental)')
+        return name.sub(canary_copy, ' (Canary)')
       end
 
       def get_type
         breadcrumb_nodes = css('a.tracking-wide')
-        return breadcrumb_nodes.last.content || 'Miscellaneous'
+        category = breadcrumb_nodes.last.content
+        is_learn_page = base_url.to_s.end_with?('learn')
+        prefix = is_learn_page ? 'Learn: ' : ''
+        return prefix + (category || 'Miscellaneous')
       end
     end
   end

+ 8 - 2
lib/docs/scrapers/react.rb

@@ -1,5 +1,7 @@
 module Docs
   class React < UrlScraper
+    include MultipleBaseUrls
+
     self.name = 'React'
     self.type = 'simple'
     self.links = {
@@ -9,8 +11,12 @@ module Docs
 
     version do
       self.release = '18.3.1'
-      # TODO add /learn
-      self.base_url = 'https://react.dev/reference'
+      host = 'https://react.dev'
+      self.base_urls = [
+        "#{host}/reference",
+        "#{host}/learn",
+      ]
+      self.initial_paths = %w(/react)
 
       html_filters.push 'react/entries_react_dev', 'react/clean_html_react_dev'