Bläddra i källkod

Update TypeScript documentation (5.3.3)

Simon Legner 1 år sedan
förälder
incheckning
ddfeed42db

+ 4 - 0
lib/docs/filters/typescript/clean_html.rb

@@ -9,6 +9,7 @@ module Docs
       }
 
       def call
+        @doc = at_css('main')
         root_page? ? root : other
         doc
       end
@@ -17,6 +18,9 @@ module Docs
         header = at_css('h1')
         header.parent.before(header).remove
 
+        # css('#above-the-fold-headline-code').remove
+        # css('#adopt-gradually-content').remove
+
         css('h4').each do |node|
           node.name = 'h2'
         end

+ 9 - 2
lib/docs/filters/typescript/entries.rb

@@ -21,8 +21,15 @@ module Docs
       def get_type
         if DEPRECATED_PAGES.include? slug
           'Handbook (deprecated)'
+        elsif slug.include?('declaration-files')
+          'Declaration Files'
+        elsif slug == 'download'
+          'Handbook'
+        elsif slug == 'why-create-typescript'
+          'Handbook'
         else
-          name
+          button = at_css('nav#sidebar > ul > li.open.highlighted > button')
+          button ? button.content : name
         end
       end
 
@@ -39,7 +46,7 @@ module Docs
       end
 
       def handbook_entries
-        css('h2').each_with_object [] do |node, entries|
+        css('h2', 'h3:has(code)').each_with_object [] do |node, entries|
           entries << ["#{name}: #{node.content}", node['id']] if node['id']
         end
       end

+ 13 - 3
lib/docs/scrapers/typescript.rb

@@ -4,12 +4,14 @@ module Docs
 
     self.name = 'TypeScript'
     self.type = 'typescript'
-    self.release = '5.1.3'
+    self.release = '5.3.3'
     self.base_urls = [
       'https://www.typescriptlang.org/docs/handbook/',
       'https://www.typescriptlang.org/'
     ]
 
+    self.root_path = 'docs/'
+
     def initial_urls
       [ 'https://www.typescriptlang.org/docs/handbook/',
         'https://www.typescriptlang.org/tsconfig' ]
@@ -22,16 +24,24 @@ module Docs
 
     html_filters.push 'typescript/entries', 'typescript/clean_html', 'title'
 
-    options[:container] = 'main'
+    options[:fix_urls_before_parse] = ->(url) do
+      url.sub! '/docs/handbook/esm-node.html', '/docs/handbook/modules/reference.html#node16-nodenext'
+      url.sub! '/docs/handbook/modules.html', '/docs/handbook/modules/introduction.html'
+      url
+    end
 
     options[:skip] = [
       'react-&-webpack.html'
     ]
 
     options[:skip_patterns] = [
+      /\Abranding/,
+      /\Acommunity/,
+      /\Adocs\Z/,
+      /\Atools/,
       /release-notes/,
       /dt\/search/,
-      /play\//
+      /play/
     ]
 
     options[:attribution] = <<-HTML