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
22 class Typescript
33 class CleanHtmlFilter < Filter
44
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+ }
1310
11+ def call
12+ root_page? ? root : other
1413 doc
1514 end
1615
@@ -24,23 +23,25 @@ module Docs · 7 unmodified lines
2423 end
2524
2625 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')
2830
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
3035
31− css('a:contains("Try")').remove
3236 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
3339 node.content = node.content
34− node['data-language'] = 'typescript'
40+ node['data-language'] = LANGUAGE_REPLACE[language] || language
3541 node.remove_attribute('class')
3642 end
3743 end
3844
39− def tsconfig
40− css('h2 a', 'h3 a').remove
41− css('svg').remove
42− end
43−
4445 end
4546 end
4647 end
lib/docs/filters/typescript/entries.rb+9−15
@@ -11,25 +11,19 @@ module Docs · 10 unmodified lines
1111 end
1212
1313 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
2116
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']]
2320 end
21+ end
2422
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']]
3026 end
31−
32− entries
3327 end
3428
3529 end
lib/docs/scrapers/typescript.rb+13−16
@@ -1,14 +1,20 @@
11 module Docs
22 class Typescript < UrlScraper
3+ include MultipleBaseUrls
4+
35 self.name = 'TypeScript'
46 self.type = 'simple'
57 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/'
1011 ]
1112
13+ def initial_urls
14+ [ 'https://www.typescriptlang.org/docs/handbook/',
15+ 'https://www.typescriptlang.org/tsconfig' ]
16+ end
17+
1218 self.links = {
1319 home: 'https://www.typescriptlang.org',
1420 code: 'https://github.com/Microsoft/TypeScript'
@@ -19,24 +25,15 @@ module Docs · 4 unmodified lines
1925 options[:container] = 'main'
2026
2127 options[:skip] = [
22− 'docs/handbook/react-&-webpack.html'
28+ 'react-&-webpack.html'
2329 ]
2430
2531 options[:skip_patterns] = [
2632 /2/,
27− /release-notes/
33+ /release-notes/,
34+ /play\//
2835 ]
2936
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−
4037 options[:attribution] = <<-HTML
4138 &copy; 2012-2020 Microsoft<br>
4239 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