History

Merge pull request #1406 from scherepn/typescript-fix

Cleanup and improve TypeScript scraper

Simon Legner committed 5 years ago

Commit 33125d22 parents 58ebf44 7e368483 files · +26 −37Browse files

Unified · Split

3 files
  1. lib/docs/filters/typescript/clean_html.rb +13 −21
  2. lib/docs/filters/typescript/entries.rb +2 −7
  3. lib/docs/scrapers/typescript.rb +11 −9
lib/docs/filters/typescript/clean_html.rb+13−21
@@ -2,20 +2,23 @@ module Docs · 1 unmodified line
22 class Typescript
33 class CleanHtmlFilter < Filter
44 def call
5+ root_page? ? root : other
6+ doc
7+ end
58
6− # Top menu bar
7− css('#top-menu').remove
8− css('.skip-to-main').remove
9+ def root
10+ header = at_css('h1')
11+ header.parent.before(header).remove
912
10− # Sidebar
11− css('#sidebar').remove
13+ css('h4').each do |node|
14+ node.name = 'h2'
15+ end
16+ end
1217
13− # Pound symbol before each title
14− css('.anchor').remove
18+ def other
19+ @doc = at_css('article > .whitespace > .markdown')
1520
16− css('#handbook-content > h2').each do |node|
17− node.name = 'h1'
18− end
21+ css('.anchor').remove
1922
2023 css('a:contains("Try")').remove
2124 css('pre').each do |node|
@@ -23,17 +26,6 @@ module Docs · 1 unmodified line
2326 node['data-language'] = 'typescript'
2427 node.remove_attribute('class')
2528 end
26−
27− # 'Next' title area
28− css('.whitespace-tight').remove
29−
30− # Right side floating box
31− css('.handbook-toc').remove
32−
33− css('#site-footer').remove
34−
35− doc
36−
3729 end
3830 end
3931 end
lib/docs/filters/typescript/entries.rb+2−7
@@ -3,7 +3,6 @@ module Docs · 2 unmodified lines
33 class EntriesFilter < Docs::EntriesFilter
44
55 def get_name
6− return 'Typescript' if current_url == root_url
76 return at_css('h2').content
87 end
98
@@ -12,13 +11,9 @@ module Docs · 2 unmodified lines
1211 end
1312
1413 def additional_entries
15− entries = []
16−
17− css('h2').each do |node|
18− entries << [node.content, node['id'], name]
14+ css('h2').each_with_object [] do |node,entries|
15+ entries << [node.content, node['id'], name]
1916 end
20−
21− entries
2217 end
2318
2419 end
lib/docs/scrapers/typescript.rb+11−9
@@ -3,23 +3,25 @@ module Docs · 2 unmodified lines
33 self.name = 'TypeScript'
44 self.type = 'simple'
55 self.release = '4.1.2'
6− self.base_url = 'https://www.typescriptlang.org/docs/handbook'
6+ self.base_url = 'https://www.typescriptlang.org/docs/handbook/'
77 self.root_path = 'index.html'
88 self.links = {
99 home: 'https://www.typescriptlang.org',
1010 code: 'https://github.com/Microsoft/TypeScript'
1111 }
1212
13− html_filters.push 'typescript/entries', 'typescript/clean_html'
13+ html_filters.push 'typescript/entries', 'typescript/clean_html', 'title'
14+
15+ options[:container] = 'main'
1416
1517 options[:skip] = [
16− '/react-&-webpack.html',
17− '/asp-net-core.html',
18− '/gulp.html',
19− '/dom-manipulation.html',
20− '/migrating-from-javascript.html',
21− '/babel-with-typescript.html',
22− '/intro.html'
18+ 'react-&-webpack.html',
19+ 'asp-net-core.html',
20+ 'gulp.html',
21+ 'dom-manipulation.html',
22+ 'migrating-from-javascript.html',
23+ 'babel-with-typescript.html',
24+ 'intro.html'
2325 ]
2426
2527 options[:skip_patterns] = [