Skip to content

Commit 7731a59

Browse files
committed
Finish Babel scraper
1 parent 1f2030d commit 7731a59

14 files changed

Lines changed: 54 additions & 93 deletions

File tree

assets/images/docs-2.png

565 Bytes
Loading

assets/images/[email protected]

1.44 KB
Loading

assets/javascripts/news.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
[
33
"2018-2-4",
4-
"New documentations: <a href=\"/jekyll/\">Jekyll</a> and <a href=\"/jsdoc/\">JSDoc</a>"
4+
"New documentations: <a href=\"/babel/\">Babel</a>, <a href=\"/jekyll/\">Jekyll</a> and <a href=\"/jsdoc/\">JSDoc</a>"
55
], [
66
"2017-11-26",
77
"New documentations: <a href=\"/bluebird/\">Bluebird</a>, <a href=\"/eslint/\">ESLint</a> and <a href=\"/homebrew/\">Homebrew</a>"

assets/javascripts/templates/pages/about_tmpl.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ credits = [
105105
'2010-2017 Caolan McMahon',
106106
'MIT',
107107
'https://raw.githubusercontent.com/caolan/async/master/LICENSE'
108+
], [
109+
'Babel',
110+
'2018 Sebastian McKenzie',
111+
'MIT',
112+
'https://raw.githubusercontent.com/babel/website/master/LICENSE'
108113
], [
109114
'Backbone.js',
110115
'2010-2016 Jeremy Ashkenas, DocumentCloud',

assets/stylesheets/application-dark.css.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
'pages/angularjs',
3636
'pages/apache',
3737
'pages/async',
38-
'pages/babel',
3938
'pages/bootstrap',
4039
'pages/c',
4140
'pages/cakephp',

assets/stylesheets/application.css.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
'pages/angularjs',
3636
'pages/apache',
3737
'pages/async',
38-
'pages/babel',
3938
'pages/bootstrap',
4039
'pages/c',
4140
'pages/cakephp',

assets/stylesheets/global/_icons.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,4 @@
169169
._icon-eslint:before { background-position: -9rem -2rem; @extend %doc-icon-2; }
170170
._icon-homebrew:before { background-position: 0 -3rem; @extend %doc-icon-2; }
171171
._icon-jekyll:before { background-position: -1rem -3rem; @extend %doc-icon-2; }
172+
._icon-babel:before { background-position: -2rem -3rem; @extend %doc-icon-2; }

assets/stylesheets/pages/_babel.scss

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/docs/filters/babel/clean_html.rb

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,34 @@ module Docs
22
class Babel
33
class CleanHtmlFilter < Filter
44
def call
5-
css('.btn-clipboard').remove
6-
7-
css('div.highlighter-rouge').each do |node|
8-
pre = node.at_css('pre')
9-
10-
# copy over the highlighting metadata
11-
match = /language-(\w+)/.match(node['class'])
12-
if match
13-
lang = match[1]
14-
if lang == 'sh'
15-
lang = 'bash'
16-
end
17-
pre['class'] = nil
18-
pre['data-language'] = lang
19-
end
20-
21-
# Remove the server-rendered syntax highlighting
22-
code = pre.at_css('code')
23-
code.content = code.text
24-
25-
# Remove the div.highlighter-rouge and div.highlight wrapping the <pre>
26-
node.add_next_sibling pre
27-
node.remove
5+
if root_page?
6+
doc.inner_html = '<h1>Babel</h1>'
7+
return doc
288
end
299

10+
header = at_css('.docs-header .col-md-12')
11+
@doc = at_css('.docs-content')
12+
doc.prepend_child(header)
3013

31-
css('blockquote').each do |node|
32-
node.name = 'div'
33-
node['class'] = '_note'
34-
end
14+
css('.btn-clipboard', '.package-links').remove
3515

36-
css((1..6).map { |n| "h#{n}" }).each do |header|
37-
return unless header.at_css('a')
38-
header.content = header.at_css('a').content
16+
css('.col-md-12', 'h1 a', 'h2 a', 'h3 a', 'h4 a', 'h5 a', 'h5 a').each do |node|
17+
node.before(node.children).remove
3918
end
4019

20+
css('div.highlighter-rouge').each do |node|
21+
pre = node.at_css('pre')
4122

42-
header = doc # .docs-content
43-
.parent # .row
44-
.parent # .container
45-
.previous_element # .docs_header
23+
lang = node['class'][/language-(\w+)/, 1]
24+
lang = 'bash' if lang == 'sh'
25+
pre['data-language'] = lang
4626

47-
toc = doc # .docs-content
48-
.parent # .row
49-
.at_css('.sidebar')
50-
toc['class'] = '_toc'
51-
toc.css('a').each do |a|
52-
a['class'] = '_toc-link'
53-
a.parent.remove if a.content == 'Community Discussion'
27+
pre.remove_attribute('class')
28+
pre.content = pre.content
29+
node.replace(pre)
5430
end
55-
toc.css('ul').attr 'class', '_toc-list'
56-
57-
h1 = header.at_css('h1')
58-
h1.content = h1.content
59-
.titleize
60-
.sub(/\bEnv\b/, 'env')
61-
.sub(/\.[A-Z]/) { |s| s.downcase }
62-
.sub(/\.babelrc/i, '.babelrc')
63-
.sub('Common Js', 'CommonJS')
64-
.sub('J Script', 'JScript')
65-
.sub(/regexp/i, 'RegExp')
66-
.sub(/api|Es(\d+)|cli|jsx?|[au]md/i) { |s| s.upcase }
6731

68-
doc.children.before toc
69-
doc.children.before header.at_css 'p'
70-
doc.children.before h1
32+
css('code').remove_attr('class')
7133

7234
doc
7335
end

lib/docs/filters/babel/entries.rb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,38 @@ module Docs
22
class Babel
33
class EntriesFilter < Docs::EntriesFilter
44
def get_name
5-
at_css('h1').content.sub /^(minify|syntax)|(transform|preset)$/i, ''
5+
at_css('h1').content
66
end
77

88
def get_type
9-
if subpath.start_with? 'plugins/preset'
9+
if subpath.start_with?('plugins/preset')
1010
'Presets'
11-
elsif subpath.start_with? 'plugins/transform'
11+
elsif subpath.start_with?('plugins/transform')
1212
'Transform Plugins'
13-
elsif subpath.start_with? 'plugins/minify'
13+
elsif subpath.start_with?('plugins/minify')
1414
'Minification'
15-
elsif subpath.start_with? 'plugins/syntax'
15+
elsif subpath.start_with?('plugins/syntax')
1616
'Syntax Plugins'
17-
elsif subpath.start_with? 'plugins'
17+
elsif subpath.start_with?('plugins')
1818
'Plugins'
19-
elsif subpath.start_with? 'usage/'
19+
elsif subpath.start_with?('usage/')
2020
'Usage'
21+
elsif subpath.start_with?('core-packages/')
22+
'Core Packages'
2123
else
22-
'Docs'
24+
'Miscellaneous'
2325
end
2426
end
2527

26-
def path
27-
super
28+
def additional_entries
29+
return [] unless slug.include?('api')
30+
31+
css('h2').each_with_object [] do |node, entries|
32+
name = node.content.strip
33+
next unless name.start_with?('babel.')
34+
name.sub! %r{\(.*}, '()'
35+
entries << [name, node['id']]
36+
end
2837
end
2938
end
3039
end

0 commit comments

Comments
 (0)