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/docs (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
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
26− end
20+ # 'Next' title area
21+ css('.whitespace-tight').remove
22+
23+ # Right side floating box
24+ css('.handbook-toc').remove
25+
26+ css('#site-footer').remove
2727
2828 doc
29+
2930 end
3031 end
3132 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