History

Merge pull request #1370 from simon04/webpack-5.6

Simon Legner committed 5 years ago

Commit 4d3bae42 parents 8581763 52910222 files · +46 −69Browse files

Unified · Split

2 files
  1. lib/docs/filters/webpack/clean_html.rb +10 −30
  2. lib/docs/scrapers/webpack.rb +36 −39
lib/docs/filters/webpack/clean_html.rb+10−30
@@ -2,48 +2,28 @@ module Docs · 1 unmodified line
2 class Webpack2 class Webpack
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 @doc = at_css('.page__content')
6
7 at_css('h1').content = 'webpack' if root_page?5 at_css('h1').content = 'webpack' if root_page?
8 6
9 css('h3').each do |node|
10 node.name = 'h2'
11 end unless at_css('h2')
12
13 css('.anchor[id]').each do |node|
14 node.parent['id'] = node['id']
15 node.remove
16 end
17
18 css('hr', '.page__edit', 'hr + h3:contains("Contributors")', 'hr + h2:contains("Contributors")',7 css('hr', '.page__edit', 'hr + h3:contains("Contributors")', 'hr + h2:contains("Contributors")',
19 '.contributors', '.icon-link', '#maintainers.header', '#maintainers.header + table',8 'td > .title', '.adjacent-links', '.contributors', '.icon-link',
20 '#maintainer.header', '#maintainer.header + table', '.page-links__link', '.page-links__gap').remove9 '#maintainers', '#maintainers + table',
10 '#maintainer', '#maintainer + table',
11 '.page-links__link', '.page-links__gap').remove
21 12
22 css('> div', '.tip-content', '.header span').each do |node|13 css('> div', '.tip-content', '.header span').each do |node|
23 node.before(node.children).remove14 node.before(node.children).remove
24 end15 end
25 16
26 css('> h1:first-child + h1').remove
27
28 css('.code-details-summary-span').each do |node|
29 node.content = node.content.remove(' (click to show)')
30 end
31
32 css('.table-wrap').each do |node|
33 css('.table-td-title').remove
34 css('.table-th').each { |n| n.name = 'th' }
35 css('.table-td').each { |n| n.name = 'td' }
36 css('.table-tr').each { |n| n.name = 'tr' }
37 css('.table-body').each { |n| n.name = 'tbody' }
38 css('.table-header').each { |n| n.name = 'thead' }
39 node.name = 'table'
40 end
41
42 css('pre > code').each do |node|17 css('pre > code').each do |node|
43 node.parent['data-language'] = node['class'][/lang-(\w+)/, 1].sub('jsx', 'js') if node['class']18 node.parent['data-language'] = 'js'
19 node.parent['data-language'] = node['class'][/language-(\w+)/, 1].sub('jsx', 'js') if node['class'] && node['class'][/language-(\w+)/, 1]
44 node.parent.content = node.parent.content20 node.parent.content = node.parent.content
45 end21 end
46 22
23 # for webpack-contrib /loaders and /plugins
24 shields = at_css('img[src*="shields.io"]')
25 shields.ancestors('p')[0].remove if shields
26
47 doc27 doc
48 end28 end
49 end29 end
lib/docs/scrapers/webpack.rb+36−39
@@ -3,49 +3,46 @@ module Docs · 2 unmodified lines
3 self.name = 'webpack'3 self.name = 'webpack'
4 self.type = 'webpack'4 self.type = 'webpack'
5 5
6 version do6 self.root_path = 'guides/'
7 self.release = '4.16.5'7 self.initial_paths = %w(
8 self.base_url = 'https://webpack.js.org/'8 concepts/
9 self.root_path = 'guides/'9 guides/
10 self.initial_paths = %w(10 api/
11 concepts/11 configuration/
12 guides/12 loaders/
13 api/13 plugins/
14 configuration/14 )
15 loaders/15 self.links = {
16 plugins/16 home: 'https://webpack.js.org/',
17 )17 code: 'https://github.com/webpack/webpack'
18 self.links = {18 }
19 home: 'https://webpack.js.org/',
20 code: 'https://github.com/webpack/webpack'
21 }
22 19
23 html_filters.push 'webpack/clean_html', 'webpack/entries'20 html_filters.push 'webpack/clean_html', 'webpack/entries'
24 21
25 options[:container] = '.page'22 options[:container] = '.page'
26 options[:trailing_slash] = false23 options[:trailing_slash] = false
27 options[:only_patterns] = [24 options[:only_patterns] = [
28 /\Aconcepts\//,25 /\Aconcepts\//,
29 /\Aguides\//,26 /\Aguides\//,
30 /\Aapi\//,27 /\Aapi\//,
31 /\Aconfiguration\//,28 /\Aconfiguration\//,
32 /\Aloaders\//,29 /\Aloaders\//,
33 /\Aplugins\//30 /\Aplugins\//
34 ]31 ]
35 32
36 options[:attribution] = <<-HTML33 options[:attribution] = <<-HTML
37 &copy; JS Foundation and other contributors<br>34 &copy; JS Foundation and other contributors<br>
38 Licensed under the Creative Commons Attribution License 4.0.35 Licensed under the Creative Commons Attribution License 4.0.
39 HTML36 HTML
37
38 version '5' do
39 self.release = '5.6.0'
40 self.base_url = 'https://webpack.js.org/'
41 end
40 42
41 ([self.root_path] + self.initial_paths).each do |path|43 version '4' do
42 stub(path) do44 self.release = '4.44.2'
43 capybara = load_capybara_selenium45 self.base_url = 'https://v4.webpack.js.org/'
44 capybara.app_host = self.base_url.origin
45 capybara.visit("#{self.base_url}#{path}")
46 capybara.execute_script('return document.body.innerHTML')
47 end
48 end
49 end46 end
50 47
51 version '1' do48 version '1' do