Restore old URLs to TypeScript documentation

pull/1435/head
Phil Scherer 4 years ago
parent 792183e823
commit 25a697ee5d

@ -2,15 +2,14 @@ module Docs
class Typescript class Typescript
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call LANGUAGE_REPLACE = {
if slug.include?('index') 'cmd' => 'shell',
root 'sh' => 'shell',
elsif slug == ('tsconfig/') 'tsx' => 'typescript+html'
tsconfig }
else
other
end
def call
root_page? ? root : other
doc doc
end end
@ -24,23 +23,25 @@ module Docs
end end
def other def other
@doc = at_css('article > .whitespace > .markdown') if base_url.path == '/docs/handbook/'
@doc = at_css('article > .whitespace > .markdown')
else # tsconfig page
@doc = at_css('.markdown > div')
css('.anchor').remove at_css('h2').remove
end
css('.anchor', 'a:contains("Try")', 'h2 a', 'h3 a', 'svg', '#full-option-list').remove
css('a:contains("Try")').remove
css('pre').each do |node| css('pre').each do |node|
language = node.at_css('.language-id') ? node.at_css('.language-id').content : 'typescript'
node.css('.language-id').remove
node.content = node.content node.content = node.content
node['data-language'] = 'typescript' node['data-language'] = LANGUAGE_REPLACE[language] || language
node.remove_attribute('class') node.remove_attribute('class')
end end
end end
def tsconfig
css('h2 a', 'h3 a').remove
css('svg').remove
end
end end
end end
end end

@ -11,25 +11,19 @@ module Docs
end end
def additional_entries def additional_entries
entries = [] base_url.path == '/' ? tsconfig_entries : handbook_entries
end
css('h2').each do |node|
if slug == 'tsconfig/'
node.css('a').remove
end
entries << [node.content, node['id'], name] def tsconfig_entries
css('h3 > code').each_with_object [] do |node, entries|
entries << [node.content, node.parent['id']]
end end
end
if slug == 'tsconfig/' def handbook_entries
css('h3').each do |node| css('h2').each_with_object [] do |node, entries|
node.css('a').remove entries << [node.content, node['id']]
entries << [node.content, node['id'], name]
end
end end
entries
end end
end end

@ -1,14 +1,20 @@
module Docs module Docs
class Typescript < UrlScraper class Typescript < UrlScraper
include MultipleBaseUrls
self.name = 'TypeScript' self.name = 'TypeScript'
self.type = 'simple' self.type = 'simple'
self.release = '4.1.3' self.release = '4.1.3'
self.base_url = 'https://www.typescriptlang.org/' self.base_urls = [
self.root_path = 'docs/handbook/index.html' 'https://www.typescriptlang.org/docs/handbook/',
self.initial_paths = [ 'https://www.typescriptlang.org/'
'tsconfig/'
] ]
def initial_urls
[ 'https://www.typescriptlang.org/docs/handbook/',
'https://www.typescriptlang.org/tsconfig' ]
end
self.links = { self.links = {
home: 'https://www.typescriptlang.org', home: 'https://www.typescriptlang.org',
code: 'https://github.com/Microsoft/TypeScript' code: 'https://github.com/Microsoft/TypeScript'
@ -19,24 +25,15 @@ module Docs
options[:container] = 'main' options[:container] = 'main'
options[:skip] = [ options[:skip] = [
'docs/handbook/react-&-webpack.html' 'react-&-webpack.html'
] ]
options[:skip_patterns] = [ options[:skip_patterns] = [
/2/, /2/,
/release-notes/ /release-notes/,
/play\//
] ]
options[:only_patterns] = [
/docs\/handbook\//,
/tsconfig\//
]
options[:fix_urls] = -> (url) do
url.gsub!(/docs\/handbook\/index.html/, "index.html")
url
end
options[:attribution] = <<-HTML options[:attribution] = <<-HTML
&copy; 2012-2020 Microsoft<br> &copy; 2012-2020 Microsoft<br>
Licensed under the Apache License, Version 2.0. Licensed under the Apache License, Version 2.0.

Loading…
Cancel
Save