diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index d480f720..ee2b3e68 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -34,6 +34,7 @@ 'pages/angularjs', 'pages/apache', 'pages/async', + 'pages/babel', 'pages/bootstrap', 'pages/c', 'pages/cakephp', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 4fdc2a14..81ab0249 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -34,6 +34,7 @@ 'pages/angularjs', 'pages/apache', 'pages/async', + 'pages/babel', 'pages/bootstrap', 'pages/c', 'pages/cakephp', diff --git a/assets/stylesheets/pages/_babel.scss b/assets/stylesheets/pages/_babel.scss new file mode 100644 index 00000000..3980bf47 --- /dev/null +++ b/assets/stylesheets/pages/_babel.scss @@ -0,0 +1,10 @@ +._babel { + @extend %simple; + ._note { + h1, h2, h3, h4, h5, h6 { + &:first-child { + margin: 0.5em 0; + } + } + } +} diff --git a/lib/docs/filters/babel/clean_html.rb b/lib/docs/filters/babel/clean_html.rb new file mode 100644 index 00000000..ff46f386 --- /dev/null +++ b/lib/docs/filters/babel/clean_html.rb @@ -0,0 +1,76 @@ +module Docs + class Babel + class CleanHtmlFilter < Filter + def call + css('.btn-clipboard').remove + + css('div.highlighter-rouge').each do |node| + pre = node.at_css('pre') + + # copy over the highlighting metadata + match = /language-(\w+)/.match(node['class']) + if match + lang = match[1] + if lang == 'sh' + lang = 'bash' + end + pre['class'] = nil + pre['data-language'] = lang + end + + # Remove the server-rendered syntax highlighting + code = pre.at_css('code') + code.content = code.text + + # Remove the div.highlighter-rouge and div.highlight wrapping the
+ node.add_next_sibling pre + node.remove + end + + + css('blockquote').each do |node| + node.name = 'div' + node['class'] = '_note' + end + + css((1..6).map { |n| "h#{n}" }).each do |header| + return unless header.at_css('a') + header.content = header.at_css('a').content + end + + + header = doc # .docs-content + .parent # .row + .parent # .container + .previous_element # .docs_header + + toc = doc # .docs-content + .parent # .row + .at_css('.sidebar') + toc['class'] = '_toc' + toc.css('a').each do |a| + a['class'] = '_toc-link' + a.parent.remove if a.content == 'Community Discussion' + end + toc.css('ul').attr 'class', '_toc-list' + + h1 = header.at_css('h1') + h1.content = h1.content + .titleize + .sub(/\bEnv\b/, 'env') + .sub(/\.[A-Z]/) { |s| s.downcase } + .sub(/\.babelrc/i, '.babelrc') + .sub('Common Js', 'CommonJS') + .sub('J Script', 'JScript') + .sub(/regexp/i, 'RegExp') + .sub(/api|Es(\d+)|cli|jsx?|[au]md/i) { |s| s.upcase } + + doc.children.before toc + doc.children.before header.at_css 'p' + doc.children.before h1 + + doc + end + end + end +end diff --git a/lib/docs/filters/babel/entries.rb b/lib/docs/filters/babel/entries.rb new file mode 100644 index 00000000..98180b34 --- /dev/null +++ b/lib/docs/filters/babel/entries.rb @@ -0,0 +1,31 @@ +module Docs + class Babel + class EntriesFilter < Docs::EntriesFilter + def get_name + at_css('h1').content.sub /^(minify|syntax)|(transform|preset)$/i, '' + end + + def get_type + if subpath.start_with? 'plugins/preset' + 'Presets' + elsif subpath.start_with? 'plugins/transform' + 'Transform Plugins' + elsif subpath.start_with? 'plugins/minify' + 'Minification' + elsif subpath.start_with? 'plugins/syntax' + 'Syntax Plugins' + elsif subpath.start_with? 'plugins' + 'Plugins' + elsif subpath.start_with? 'usage/' + 'Usage' + else + 'Docs' + end + end + + def path + super + end + end + end +end diff --git a/lib/docs/scrapers/babel.rb b/lib/docs/scrapers/babel.rb new file mode 100644 index 00000000..39495dcf --- /dev/null +++ b/lib/docs/scrapers/babel.rb @@ -0,0 +1,31 @@ +module Docs + class Babel < UrlScraper + self.type = 'babel' + self.base_url = 'http://babeljs.io/docs/' + self.root_path = '/plugins/' + self.release = '6.26.0' + self.initial_paths = %w[faq tour usage/babel-register core-packages editors usage/caveats] + self.links = { + home: 'https://babeljs.io/', + code: 'https://github.com/babel/babel' + } + + html_filters.push 'babel/clean_html', 'babel/entries' + + options[:trailing_slash] = true + options[:container] = '.docs-content' + options[:skip] = %w{setup/ community/videos/} + options[:fix_urls] = ->(url) do + return url unless url.start_with? self.base_url + url.sub %r{/(index\.\w+)?$}, '' + end + + options[:attribution] = <<-HTML + © 2018 Sebastian McKenzie
+ Licensed under the + + MIT License + + HTML + end +end