History

Typescript: add 'tsconfig' section and update scraper to 4.1.3

MasterEnoc committed 5 years ago

Commit 2f5ed721 parent 6a4c1f23 files · +53 −8Browse files

Unified · Split

3 files
  1. lib/docs/filters/typescript/clean_html.rb +15 −1
  2. lib/docs/filters/typescript/entries.rb +18 −2
  3. lib/docs/scrapers/typescript.rb +20 −5
lib/docs/filters/typescript/clean_html.rb+15−1
@@ -1,8 +1,16 @@
11 module Docs
22 class Typescript
33 class CleanHtmlFilter < Filter
4+
45 def call
5− root_page? ? root : other
6+ if slug.include?('index')
7+ root
8+ elsif slug == ('tsconfig/')
9+ tsconfig
10+ else
11+ other
12+ end
13+
614 doc
715 end
816
@@ -27,6 +35,12 @@ module Docs · 18 unmodified lines
2735 node.remove_attribute('class')
2836 end
2937 end
38+
39+ def tsconfig
40+ css('h2 a', 'h3 a').remove
41+ css('svg').remove
42+ end
43+
3044 end
3145 end
3246 end
lib/docs/filters/typescript/entries.rb+18−2
@@ -3,7 +3,7 @@ module Docs · 2 unmodified lines
33 class EntriesFilter < Docs::EntriesFilter
44
55 def get_name
6− return at_css('h2').content
6+ at_css('h1') ? at_css('h1').content : at_css('h2').content
77 end
88
99 def get_type
@@ -11,9 +11,25 @@ module Docs · 1 unmodified line
1111 end
1212
1313 def additional_entries
14− css('h2').each_with_object [] do |node,entries|
14+ entries = []
15+
16+ css('h2').each do |node|
17+
18+ if slug == 'tsconfig/'
19+ node.css('a').remove
20+ end
21+
1522 entries << [node.content, node['id'], name]
1623 end
24+
25+ if slug == 'tsconfig/'
26+ css('h3').each do |node|
27+ node.css('a').remove
28+ entries << [node.content, node['id'], name]
29+ end
30+ end
31+
32+ entries
1733 end
1834
1935 end
lib/docs/scrapers/typescript.rb+20−5
@@ -2,9 +2,13 @@ module Docs · 1 unmodified line
22 class Typescript < UrlScraper
33 self.name = 'TypeScript'
44 self.type = 'simple'
5− self.release = '4.1.2'
6− self.base_url = 'https://www.typescriptlang.org/docs/handbook/'
7− self.root_path = 'index.html'
5+ 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/'
10+ ]
11+
812 self.links = {
913 home: 'https://www.typescriptlang.org',
1014 code: 'https://github.com/Microsoft/TypeScript'
@@ -15,14 +19,24 @@ module Docs · 4 unmodified lines
1519 options[:container] = 'main'
1620
1721 options[:skip] = [
18− 'react-&-webpack.html',
22+ 'docs/handbook/react-&-webpack.html'
1923 ]
2024
2125 options[:skip_patterns] = [
2226 /2/,
23− /release-notes/,
27+ /release-notes/
28+ ]
29+
30+ options[:only_patterns] = [
31+ /docs\/handbook\//,
32+ /tsconfig\//
2433 ]
2534
35+ options[:fix_urls] = -> (url) do
36+ url.gsub!(/docs\/handbook\/index.html/, "index.html")
37+ url
38+ end
39+
2640 options[:attribution] = <<-HTML
2741 &copy; 2012-2020 Microsoft<br>
2842 Licensed under the Apache License, Version 2.0.
@@ -31,5 +45,6 @@ module Docs · 2 unmodified lines
3145 def get_latest_version(opts)
3246 get_latest_github_release('Microsoft', 'TypeScript', opts)
3347 end
48+
3449 end
3550 end