History

Update Vite documentation (2.8.3)

Simon Legner committed 4 years ago

Commit d6aed8e1 parent 028d0283 files · +75 −3Browse files

Unified · Split

3 files
  1. lib/docs/filters/vite/clean_html.rb +50 −0
  2. lib/docs/filters/vite/entries.rb +23 −0
  3. lib/docs/scrapers/vite.rb +2 −3
lib/docs/filters/vite/clean_html.rb+50−0
@@ -0,0 +1,50 @@
1+module Docs
2+ class Vite
3+ class CleanHtmlFilter < Filter
4+ def call
5+ return '<h1>Vite</h1>' if root_page?
6+ @doc = at_css('main .content > div')
7+
8+ css('.demo', '.guide-links', '.footer', '#ad').remove
9+ css('.header-anchor', '.page-edit', '.page-nav').remove
10+
11+ css('.custom-block-title').each do |node|
12+ node.name = 'strong'
13+ end
14+
15+ # Remove CodePen div
16+ css('.codepen').each do |node|
17+ next if node.previous_element.nil?
18+ span = node.css('span:contains("See the Pen")').remove
19+ node.previous_element.add_child(' ')
20+ node.previous_element.add_child(span)
21+ node.remove
22+ end
23+
24+ # Remove code highlighting
25+ css('figure').each do |node|
26+ node.name = 'pre'
27+ node.content = node.at_css('td.code pre').css('.line').map(&:content).join("\n")
28+ node['data-language'] = node['class'][/highlight (\w+)/, 1]
29+ end
30+
31+ css('.line-numbers-wrapper').remove
32+ css('pre').each do |node|
33+ node.content = node.content.strip
34+ node['data-language'] = 'javascript'
35+ end
36+
37+ css('iframe').each do |node|
38+ node['sandbox'] = 'allow-forms allow-scripts allow-same-origin'
39+ node.remove if node['src'][/player.vimeo.com/] # https://v3.vuejs.org/guide/migration/introduction.html#overview
40+ end
41+
42+ css('details').each do |node|
43+ node.name = 'div'
44+ end
45+
46+ doc
47+ end
48+ end
49+ end
50+end
lib/docs/filters/vite/entries.rb+23−0
@@ -0,0 +1,23 @@
1+module Docs
2+ class Vite
3+ class EntriesFilter < Docs::EntriesFilter
4+ def get_name
5+ name = at_css('h1').content
6+ name.sub! %r{\s*#\s*}, ''
7+ name
8+ end
9+
10+ def get_type
11+ at_css('header nav .item.active').content.strip
12+ end
13+
14+ def additional_entries
15+ css('h2, h3').each_with_object [] do |node, entries|
16+ type = node.content.strip
17+ type.sub! %r{\s*#\s*}, ''
18+ entries << ["#{name}: #{type}", node['id']]
19+ end
20+ end
21+ end
22+ end
23+end
lib/docs/scrapers/vite.rb+2−3
@@ -8,7 +8,6 @@ module Docs · 7 unmodified lines
88 code: 'https://github.com/vitejs/vite'
99 }
1010
11− options[:container] = 'main'
1211 options[:root_title] = 'Vite'
1312
1413 options[:attribution] = <<-HTML
@@ -16,10 +15,10 @@ module Docs · 1 unmodified line
1615 Licensed under the MIT License.
1716 HTML
1817
19− self.release = '2.7.5'
18+ self.release = '2.8.3'
2019 self.base_url = 'https://vitejs.dev/'
2120 self.initial_paths = %w(guide/)
22− html_filters.push 'vue/entries_v3', 'vue/clean_html'
21+ html_filters.push 'vite/entries', 'vite/clean_html'
2322
2423 def get_latest_version(opts)
2524 get_npm_version('vite', opts)