History

Restore old URLs to TypeScript documentation

Phil Scherer committed 5 years ago

Commit 25a697e1 parent 792183e3 files · +40 −48Browse files

Unified · Split

3 files
  1. lib/docs/filters/typescript/clean_html.rb +18 −17
  2. lib/docs/filters/typescript/entries.rb +9 −15
  3. lib/docs/scrapers/typescript.rb +13 −16
lib/docs/filters/typescript/clean_html.rb+18−17
@@ -2,15 +2,14 @@ module Docs · 1 unmodified line
2 class Typescript2 class Typescript
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 4
5 def call5 LANGUAGE_REPLACE = {
6 if slug.include?('index')6 'cmd' => 'shell',
7 root7 'sh' => 'shell',
8 elsif slug == ('tsconfig/')8 'tsx' => 'typescript+html'
9 tsconfig9 }
10 else
11 other
12 end
13 10
11 def call
12 root_page? ? root : other
14 doc13 doc
15 end14 end
16 15
@@ -24,23 +23,25 @@ module Docs · 7 unmodified lines
24 end23 end
25 24
26 def other25 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').remove31 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 css('pre').each do |node|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 node.content = node.content39 node.content = node.content
34 node['data-language'] = 'typescript'40 node['data-language'] = LANGUAGE_REPLACE[language] || language
35 node.remove_attribute('class')41 node.remove_attribute('class')
36 end42 end
37 end43 end
38 44
39 def tsconfig
40 css('h2 a', 'h3 a').remove
41 css('svg').remove
42 end
43
44 end45 end
45 end46 end
46end47end
lib/docs/filters/typescript/entries.rb+9−15
@@ -11,25 +11,19 @@ module Docs · 10 unmodified lines
11 end11 end
12 12
13 def additional_entries13 def additional_entries
14 entries = []14 base_url.path == '/' ? tsconfig_entries : handbook_entries
15 15 end
16 css('h2').each do |node|
17
18 if slug == 'tsconfig/'
19 node.css('a').remove
20 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 end20 end
21 end
24 22
25 if slug == 'tsconfig/'23 def handbook_entries
26 css('h3').each do |node|24 css('h2').each_with_object [] do |node, entries|
27 node.css('a').remove25 entries << [node.content, node['id']]
28 entries << [node.content, node['id'], name]
29 end
30 end26 end
31
32 entries
33 end27 end
34 28
35 end29 end
lib/docs/scrapers/typescript.rb+13−16
@@ -1,14 +1,20 @@
1module Docs1module Docs
2 class Typescript < UrlScraper2 class Typescript < UrlScraper
3 include MultipleBaseUrls
4
3 self.name = 'TypeScript'5 self.name = 'TypeScript'
4 self.type = 'simple'6 self.type = 'simple'
5 self.release = '4.1.3'7 self.release = '4.1.3'
6 self.base_url = 'https://www.typescriptlang.org/'8 self.base_urls = [
7 self.root_path = 'docs/handbook/index.html'9 'https://www.typescriptlang.org/docs/handbook/',
8 self.initial_paths = [10 'https://www.typescriptlang.org/'
9 'tsconfig/'
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 self.links = {18 self.links = {
13 home: 'https://www.typescriptlang.org',19 home: 'https://www.typescriptlang.org',
14 code: 'https://github.com/Microsoft/TypeScript'20 code: 'https://github.com/Microsoft/TypeScript'
@@ -19,24 +25,15 @@ module Docs · 4 unmodified lines
19 options[:container] = 'main'25 options[:container] = 'main'
20 26
21 options[:skip] = [27 options[:skip] = [
22 'docs/handbook/react-&-webpack.html'28 'react-&-webpack.html'
23 ]29 ]
24 30
25 options[:skip_patterns] = [31 options[:skip_patterns] = [
26 /2/,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 options[:attribution] = <<-HTML37 options[:attribution] = <<-HTML
41 &copy; 2012-2020 Microsoft<br>38 &copy; 2012-2020 Microsoft<br>
42 Licensed under the Apache License, Version 2.0.39 Licensed under the Apache License, Version 2.0.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t