History

Merge pull request #1354 from MasterEnoc/typescript

Update Typescript to 4.0.5

Simon Legner committed 5 years ago

Commit 6e8441d2 parents 8c69bf4 87f97d64 files · +56 −52Browse files

Unified · Split

4 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +1 −1
  2. lib/docs/filters/typescript/clean_html.rb +23 −15
  3. lib/docs/filters/typescript/entries.rb +10 −25
  4. lib/docs/scrapers/typescript.rb +22 −11
assets/javascripts/templates/pages/about_tmpl.coffee+1−1
@@ -783,7 +783,7 @@ credits = [ · 782 unmodified lines
783783 'https://twig.symfony.com/license'
784784 ], [
785785 'TypeScript',
786− '2012-2019 Microsoft',
786+ '2012-2020 Microsoft',
787787 'Apache',
788788 'https://raw.githubusercontent.com/Microsoft/TypeScript-Handbook/master/LICENSE'
789789 ], [
lib/docs/filters/typescript/clean_html.rb+23−15
@@ -2,30 +2,38 @@ module Docs · 1 unmodified line
22 class Typescript
33 class CleanHtmlFilter < Filter
44 def call
5− @doc = at_css('.doc-content-container')
65
7− if root_page?
8− at_css('h1').content = 'TypeScript Documentation'
9− end
6+ # Top menu bar
7+ css('#top-menu').remove
8+ css('.skip-to-main').remove
109
11− css('.xs-toc-container').remove
12− css('.anchor-hash').remove
10+ # Sidebar
11+ css('#sidebar').remove
1312
14− css('article h1').each do |node|
15− node.name = 'h2'
16− end
13+ # Pound symbol before each title
14+ css('.anchor').remove
1715
18− css('> header', '> article').each do |node|
19− node.before(node.children).remove
16+ css('#handbook-content > h2').each do |node|
17+ node.name = 'h1'
2018 end
2119
22− css('pre > code').each do |node|
23− node.parent['data-language'] = node['class'].sub('ts', 'typescript').sub('js', 'javascript').remove('language-') if node['class']
24− node.content = node.content.gsub(' ', ' ')
25− node.before(node.children).remove
20+ css('a:contains("Try")').remove
21+ css('pre').each do |node|
22+ node.content = node.content
23+ node['data-language'] = 'typescript'
24+ node.remove_attribute('class')
2625 end
2726
27+ # 'Next' title area
28+ css('.whitespace-tight').remove
29+
30+ # Right side floating box
31+ css('.handbook-toc').remove
32+
33+ css('#site-footer').remove
34+
2835 doc
36+
2937 end
3038 end
3139 end
lib/docs/filters/typescript/entries.rb+10−25
@@ -1,41 +1,26 @@
11 module Docs
22 class Typescript
33 class EntriesFilter < Docs::EntriesFilter
4+
45 def get_name
5− name = at_css('h1').content.strip
6− name.sub! ' and ', ' & '
7− name
6+ return 'Typescript' if current_url == root_url
7+ return at_css('h2').content
88 end
99
1010 def get_type
11− return 'Declaration Files' if subpath.include?('declaration-files')
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
11+ name
1612 end
1713
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−
2014 def additional_entries
21− return [] unless slug.start_with?('handbook')
22− return [] if slug.include?('release-notes')
23− return [] if slug == 'handbook/writing-definition-files'
15+ entries = []
2416
25− css('.post-content h1, .post-content h2').each_with_object [] do |node, entries|
26− next if node.next_element.try(:name) == 'h2'
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']]
17+ css('h2').each do |node|
18+ entries << [node.content, node['id'], name]
3719 end
20+
21+ entries
3822 end
23+
3924 end
4025 end
4126 end
lib/docs/scrapers/typescript.rb+22−11
@@ -2,9 +2,9 @@ module Docs · 1 unmodified line
22 class Typescript < UrlScraper
33 self.name = 'TypeScript'
44 self.type = 'simple'
5− self.release = '3.7.4'
6− self.base_url = 'https://www.typescriptlang.org/docs/'
7− self.root_path = 'tutorial.html'
5+ self.release = '4.0.5'
6+ self.base_url = 'https://www.typescriptlang.org/docs/handbook'
7+ self.root_path = 'index.html'
88 self.links = {
99 home: 'https://www.typescriptlang.org',
1010 code: 'https://github.com/Microsoft/TypeScript'
@@ -12,16 +12,27 @@ module Docs · 1 unmodified line
1212
1313 html_filters.push 'typescript/entries', 'typescript/clean_html'
1414
15− options[:container] = '#doc-content'
16− options[:skip] = %w(home.html handbook/release-notes/overview.html)
17− options[:skip_link] = ->(node) { node.parent.parent['class'] == 'dropdown-menu' }
18− options[:fix_urls] = ->(url) {
19− url.sub!(/(\w+)\.md/) { "#{$1.downcase}.html" }
20− url
21− }
15+ options[:skip] = [
16+ '/react-&-webpack.html',
17+ '/asp-net-core.html',
18+ '/gulp.html',
19+ '/dom-manipulation.html',
20+ '/migrating-from-javascript.html',
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+ ]
2233
2334 options[:attribution] = <<-HTML
24− &copy; 2012-2019 Microsoft<br>
35+ &copy; 2012-2020 Microsoft<br>
2536 Licensed under the Apache License, Version 2.0.
2637 HTML
2738