Showing the changes to lib/docs (3 of 3 files). Show all
Unified · Split
| @@ -2,30 +2,31 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Typescript |
| 3 | 3 | class CleanHtmlFilter < Filter |
| 4 | 4 | def call |
| 5 | − @doc = at_css('.doc-content-container') | |
| 6 | 5 | |
| 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 | |
| 10 | 9 | |
| 11 | − css('.xs-toc-container').remove | |
| 12 | − css('.anchor-hash').remove | |
| 10 | + # Sidebar | |
| 11 | + css('#sidebar').remove | |
| 13 | 12 | |
| 14 | − css('article h1').each do |node| | |
| 15 | − node.name = 'h2' | |
| 16 | − end | |
| 13 | + # Pound symbol before each title | |
| 14 | + css('.anchor').remove | |
| 17 | 15 | |
| 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' | |
| 20 | 18 | end |
| 21 | 19 | |
| 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 | |
| 27 | 27 | |
| 28 | 28 | doc |
| 29 | + | |
| 29 | 30 | end |
| 30 | 31 | end |
| 31 | 32 | end |
| @@ -1,41 +1,26 @@ | ||
| 1 | 1 | module Docs |
| 2 | 2 | class Typescript |
| 3 | 3 | class EntriesFilter < Docs::EntriesFilter |
| 4 | + | |
| 4 | 5 | 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 | |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 10 | 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 | |
| 16 | 12 | 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 | 14 | 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 = [] | |
| 24 | 16 | |
| 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] | |
| 37 | 19 | end |
| 20 | + | |
| 21 | + entries | |
| 38 | 22 | end |
| 23 | + | |
| 39 | 24 | end |
| 40 | 25 | end |
| 41 | 26 | end |
| @@ -2,9 +2,9 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Typescript < UrlScraper |
| 3 | 3 | self.name = 'TypeScript' |
| 4 | 4 | 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' | |
| 8 | 8 | self.links = { |
| 9 | 9 | home: 'https://www.typescriptlang.org', |
| 10 | 10 | code: 'https://github.com/Microsoft/TypeScript' |
| @@ -12,16 +12,27 @@ module Docs · 1 unmodified line | ||
| 12 | 12 | |
| 13 | 13 | html_filters.push 'typescript/entries', 'typescript/clean_html' |
| 14 | 14 | |
| 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 | + ] | |
| 22 | 33 | |
| 23 | 34 | options[:attribution] = <<-HTML |
| 24 | − © 2012-2019 Microsoft<br> | |
| 35 | + © 2012-2020 Microsoft<br> | |
| 25 | 36 | Licensed under the Apache License, Version 2.0. |
| 26 | 37 | HTML |
| 27 | 38 | |