Unified · Split
| @@ -2,15 +2,14 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Typescript |
| 3 | 3 | class CleanHtmlFilter < Filter |
| 4 | 4 | |
| 5 | − def call | |
| 6 | − if slug.include?('index') | |
| 7 | − root | |
| 8 | − elsif slug == ('tsconfig/') | |
| 9 | − tsconfig | |
| 10 | − else | |
| 11 | − other | |
| 12 | − end | |
| 5 | + LANGUAGE_REPLACE = { | |
| 6 | + 'cmd' => 'shell', | |
| 7 | + 'sh' => 'shell', | |
| 8 | + 'tsx' => 'typescript+html' | |
| 9 | + } | |
| 13 | 10 | |
| 11 | + def call | |
| 12 | + root_page? ? root : other | |
| 14 | 13 | doc |
| 15 | 14 | end |
| 16 | 15 | |
| @@ -24,23 +23,25 @@ module Docs · 7 unmodified lines | ||
| 24 | 23 | end |
| 25 | 24 | |
| 26 | 25 | def other |
| 27 | − @doc = at_css('article > .whitespace > .markdown') | |
| 26 | + if base_url.path == '/docs/handbook/' | |
| 27 | + @doc = at_css('article > .whitespace > .markdown') | |
| 28 | + else # tsconfig page | |
| 29 | + @doc = at_css('.markdown > div') | |
| 28 | 30 | |
| 29 | − css('.anchor').remove | |
| 31 | + at_css('h2').remove | |
| 32 | + end | |
| 33 | + | |
| 34 | + css('.anchor', 'a:contains("Try")', 'h2 a', 'h3 a', 'svg', '#full-option-list').remove | |
| 30 | 35 | |
| 31 | − css('a:contains("Try")').remove | |
| 32 | 36 | css('pre').each do |node| |
| 37 | + language = node.at_css('.language-id') ? node.at_css('.language-id').content : 'typescript' | |
| 38 | + node.css('.language-id').remove | |
| 33 | 39 | node.content = node.content |
| 34 | − node['data-language'] = 'typescript' | |
| 40 | + node['data-language'] = LANGUAGE_REPLACE[language] || language | |
| 35 | 41 | node.remove_attribute('class') |
| 36 | 42 | end |
| 37 | 43 | end |
| 38 | 44 | |
| 39 | − def tsconfig | |
| 40 | − css('h2 a', 'h3 a').remove | |
| 41 | − css('svg').remove | |
| 42 | − end | |
| 43 | − | |
| 44 | 45 | end |
| 45 | 46 | end |
| 46 | 47 | end |
| @@ -11,25 +11,19 @@ module Docs · 10 unmodified lines | ||
| 11 | 11 | end |
| 12 | 12 | |
| 13 | 13 | def additional_entries |
| 14 | − entries = [] | |
| 15 | − | |
| 16 | − css('h2').each do |node| | |
| 17 | − | |
| 18 | − if slug == 'tsconfig/' | |
| 19 | − node.css('a').remove | |
| 20 | − end | |
| 14 | + base_url.path == '/' ? tsconfig_entries : handbook_entries | |
| 15 | + end | |
| 21 | 16 | |
| 22 | − entries << [node.content, node['id'], name] | |
| 17 | + def tsconfig_entries | |
| 18 | + css('h3 > code').each_with_object [] do |node, entries| | |
| 19 | + entries << [node.content, node.parent['id']] | |
| 23 | 20 | end |
| 21 | + end | |
| 24 | 22 | |
| 25 | − if slug == 'tsconfig/' | |
| 26 | − css('h3').each do |node| | |
| 27 | − node.css('a').remove | |
| 28 | − entries << [node.content, node['id'], name] | |
| 29 | − end | |
| 23 | + def handbook_entries | |
| 24 | + css('h2').each_with_object [] do |node, entries| | |
| 25 | + entries << [node.content, node['id']] | |
| 30 | 26 | end |
| 31 | − | |
| 32 | − entries | |
| 33 | 27 | end |
| 34 | 28 | |
| 35 | 29 | end |
| @@ -1,14 +1,20 @@ | ||
| 1 | 1 | module Docs |
| 2 | 2 | class Typescript < UrlScraper |
| 3 | + include MultipleBaseUrls | |
| 4 | + | |
| 3 | 5 | self.name = 'TypeScript' |
| 4 | 6 | self.type = 'simple' |
| 5 | 7 | self.release = '4.1.3' |
| 6 | − self.base_url = 'https://www.typescriptlang.org/' | |
| 7 | − self.root_path = 'docs/handbook/index.html' | |
| 8 | − self.initial_paths = [ | |
| 9 | − 'tsconfig/' | |
| 8 | + self.base_urls = [ | |
| 9 | + 'https://www.typescriptlang.org/docs/handbook/', | |
| 10 | + 'https://www.typescriptlang.org/' | |
| 10 | 11 | ] |
| 11 | 12 | |
| 13 | + def initial_urls | |
| 14 | + [ 'https://www.typescriptlang.org/docs/handbook/', | |
| 15 | + 'https://www.typescriptlang.org/tsconfig' ] | |
| 16 | + end | |
| 17 | + | |
| 12 | 18 | self.links = { |
| 13 | 19 | home: 'https://www.typescriptlang.org', |
| 14 | 20 | code: 'https://github.com/Microsoft/TypeScript' |
| @@ -19,24 +25,15 @@ module Docs · 4 unmodified lines | ||
| 19 | 25 | options[:container] = 'main' |
| 20 | 26 | |
| 21 | 27 | options[:skip] = [ |
| 22 | − 'docs/handbook/react-&-webpack.html' | |
| 28 | + 'react-&-webpack.html' | |
| 23 | 29 | ] |
| 24 | 30 | |
| 25 | 31 | options[:skip_patterns] = [ |
| 26 | 32 | /2/, |
| 27 | − /release-notes/ | |
| 33 | + /release-notes/, | |
| 34 | + /play\// | |
| 28 | 35 | ] |
| 29 | 36 | |
| 30 | − options[:only_patterns] = [ | |
| 31 | − /docs\/handbook\//, | |
| 32 | − /tsconfig\// | |
| 33 | − ] | |
| 34 | − | |
| 35 | − options[:fix_urls] = -> (url) do | |
| 36 | − url.gsub!(/docs\/handbook\/index.html/, "index.html") | |
| 37 | − url | |
| 38 | − end | |
| 39 | − | |
| 40 | 37 | options[:attribution] = <<-HTML |
| 41 | 38 | © 2012-2020 Microsoft<br> |
| 42 | 39 | Licensed under the Apache License, Version 2.0. |