From ddfeed42db91ff9ee5b888b824681d5895b9ec39 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sun, 7 Jan 2024 10:25:07 +0100 Subject: [PATCH] Update TypeScript documentation (5.3.3) --- lib/docs/filters/typescript/clean_html.rb | 4 ++++ lib/docs/filters/typescript/entries.rb | 11 +++++++++-- lib/docs/scrapers/typescript.rb | 16 +++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/docs/filters/typescript/clean_html.rb b/lib/docs/filters/typescript/clean_html.rb index f7ba2b33..87e2296e 100644 --- a/lib/docs/filters/typescript/clean_html.rb +++ b/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 diff --git a/lib/docs/filters/typescript/entries.rb b/lib/docs/filters/typescript/entries.rb index c2ad3b0e..2a9e1d9d 100644 --- a/lib/docs/filters/typescript/entries.rb +++ b/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 diff --git a/lib/docs/scrapers/typescript.rb b/lib/docs/scrapers/typescript.rb index 9156269b..a072467d 100644 --- a/lib/docs/scrapers/typescript.rb +++ b/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