History

Update Typescript to 4.0.5

MasterEnoc committed 5 years ago

Commit 5ced4ea1 parent 095e6d43 files · +49 −52Browse files

Showing the changes to lib (3 of 3 files). Show all

Unified · Split

3 files
  1. lib/docs/filters/typescript/clean_html.rb +17 −16
  2. lib/docs/filters/typescript/entries.rb +10 −25
  3. lib/docs/scrapers/typescript.rb +22 −11
lib/docs/filters/typescript/clean_html.rb+17−16
@@ -2,30 +2,31 @@ module Docs · 1 unmodified line
2 class Typescript2 class Typescript
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 @doc = at_css('.doc-content-container')
6 5
7 if root_page?6 # Top menu bar
8 at_css('h1').content = 'TypeScript Documentation'7 css('#top-menu').remove
9 end8 css('.skip-to-main').remove
10 9
11 css('.xs-toc-container').remove10 # Sidebar
12 css('.anchor-hash').remove11 css('#sidebar').remove
13 12
14 css('article h1').each do |node|13 # Pound symbol before each title
15 node.name = 'h2'14 css('.anchor').remove
16 end
17 15
18 css('> header', '> article').each do |node|16 css('#handbook-content > h2').each do |node|
19 node.before(node.children).remove17 node.name = 'h1'
20 end18 end
21 19
22 css('pre > code').each do |node|20 # 'Next' title area
23 node.parent['data-language'] = node['class'].sub('ts', 'typescript').sub('js', 'javascript').remove('language-') if node['class']21 css('.whitespace-tight').remove
24 node.content = node.content.gsub(' ', ' ')22
25 node.before(node.children).remove23 # Right side floating box
26 end24 css('.handbook-toc').remove
25
26 css('#site-footer').remove
27 27
28 doc28 doc
29
29 end30 end
30 end31 end
31 end32 end
lib/docs/filters/typescript/entries.rb+10−25
@@ -1,41 +1,26 @@
1module Docs1module Docs
2 class Typescript2 class Typescript
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4
4 def get_name5 def get_name
5 name = at_css('h1').content.strip6 return 'Typescript' if current_url == root_url
6 name.sub! ' and ', ' & '7 return at_css('h2').content
7 name
8 end8 end
9 9
10 def get_type10 def get_type
11 return 'Declaration Files' if subpath.include?('declaration-files')11 name
12 return 'Project Configuration' if slug == 'handbook/configuring-watch'
13 type = at_css('#main-nav a.active').ancestors('.panel').first.at_css('> a').content
14 type = name if type == 'Handbook'
15 type
16 end12 end
17 13
18 SKIP_ENTRIES = ['Introduction', 'A note', 'A Note', ', and', 'Techniques', ' Concepts', 'Hello World', 'Working with', 'Our ', 'Implementing ', 'Difference between', 'Basic', 'sample', 'Questions', 'Example', 'Export as close', 'Red Flags', 'First steps', 'Pitfalls', 'Well-known', 'Starting out', 'Comparing ', 'Do not', 'Trade-off', ' vs', 'Overview', 'Related', 'Table of contents']
19
20 def additional_entries14 def additional_entries
21 return [] unless slug.start_with?('handbook')15 entries = []
22 return [] if slug.include?('release-notes')
23 return [] if slug == 'handbook/writing-definition-files'
24 16
25 css('.post-content h1, .post-content h2').each_with_object [] do |node, entries|17 css('h2').each do |node|
26 next if node.next_element.try(:name) == 'h2'18 entries << [node.content, node['id'], name]
27 node.css('.anchor-hash').remove
28 name = node.content.strip
29 next if name.length > 40
30 next if name == self.name || SKIP_ENTRIES.any? { |str| name.include?(str) }
31 name.remove! %r{\A#{self.name.remove(/s\z/)}s? }
32 name.sub! 'for..of', 'for...of'
33 name.remove! 'Symbol.'
34 name.remove! '/// '
35 name.prepend "#{self.name}: "
36 entries << [name, node['id']]
37 end19 end
20
21 entries
38 end22 end
23
39 end24 end
40 end25 end
41end26end
lib/docs/scrapers/typescript.rb+22−11
@@ -2,9 +2,9 @@ module Docs · 1 unmodified line
2 class Typescript < UrlScraper2 class Typescript < UrlScraper
3 self.name = 'TypeScript'3 self.name = 'TypeScript'
4 self.type = 'simple'4 self.type = 'simple'
5 self.release = '3.7.4'5 self.release = '4.0.5'
6 self.base_url = 'https://www.typescriptlang.org/docs/'6 self.base_url = 'https://www.typescriptlang.org/docs/handbook'
7 self.root_path = 'tutorial.html'7 self.root_path = 'index.html'
8 self.links = {8 self.links = {
9 home: 'https://www.typescriptlang.org',9 home: 'https://www.typescriptlang.org',
10 code: 'https://github.com/Microsoft/TypeScript'10 code: 'https://github.com/Microsoft/TypeScript'
@@ -12,16 +12,27 @@ module Docs · 1 unmodified line
12 12
13 html_filters.push 'typescript/entries', 'typescript/clean_html'13 html_filters.push 'typescript/entries', 'typescript/clean_html'
14 14
15 options[:container] = '#doc-content'15 options[:skip] = [
16 options[:skip] = %w(home.html handbook/release-notes/overview.html)16 '/react-&-webpack.html',
17 options[:skip_link] = ->(node) { node.parent.parent['class'] == 'dropdown-menu' }17 '/asp-net-core.html',
18 options[:fix_urls] = ->(url) {18 '/gulp.html',
19 url.sub!(/(\w+)\.md/) { "#{$1.downcase}.html" }19 '/dom-manipulation.html',
20 url20 '/migrating-from-javascript.html',
21 }21 '/babel-with-typescript.html',
22 '/intro.html'
23 ]
24
25 options[:skip_patterns] = [
26 /2/,
27 /typescript-/,
28 /release-notes/,
29 /introduction/,
30 /tutorials/,
31 /intro.html/
32 ]
22 33
23 options[:attribution] = <<-HTML34 options[:attribution] = <<-HTML
24 &copy; 2012-2019 Microsoft<br>35 &copy; 2012-2020 Microsoft<br>
25 Licensed under the Apache License, Version 2.0.36 Licensed under the Apache License, Version 2.0.
26 HTML37 HTML
27 38