History

updated yarn version (3.1.1 > 4.5.1)

Rui Jiang committed 1 year ago

Commit 2216cb41 parent c7885d43 files · +22 −55Browse files

Unified · Split

3 files
  1. lib/docs/filters/yarn/clean_html_berry.rb +7 −34
  2. lib/docs/filters/yarn/entries_berry.rb +2 −17
  3. lib/docs/scrapers/yarn.rb +13 −4
lib/docs/filters/yarn/clean_html_berry.rb+7−34
@@ -2,45 +2,18 @@ module Docs · 1 unmodified line
2 class Yarn2 class Yarn
3 class CleanHtmlBerryFilter < Filter3 class CleanHtmlBerryFilter < Filter
4 def call4 def call
5 if slug.empty?5 @doc = at_css('main .container div.theme-doc-markdown.markdown')
6 @doc = at_css('main')
7 css(
8 (['div:first-child'] * 3).join('>'), # Tagline
9 'img',
10 'hr', # Footer
11 'hr + div', # Footer
12 ).remove
13
14 css('a').each do |link|
15 link.name = 'div'
16 link.css('h3').each do |node|
17 node.replace("<h2><a href='#{link['href']}'>#{node.content}</a></h2>")
18 end
19 end
20
21 return doc
22 end
23
24 @doc = at_css('article')
25 # Heading & edit link
26 css('h1', 'h1 + a').remove unless slug.start_with?('configuration')
27
28 if slug.start_with?('cli')
29 css('.header-code').each do |node|
30 node.name = 'span'
31 end
32 end
33
34 if slug.start_with?('configuration')
35 css('h1', 'h2').each do |node|
36 node.name = node.name.sub(/\d/) { |i| i.to_i + 1 }
37 end
38 end
39 6
40 css('*').each do |node|7 css('*').each do |node|
41 node.remove_attribute('style')8 node.remove_attribute('style')
42 end9 end
43 10
11 css('pre').each do |node|
12 lang = node['class'][/language-(\w+)/, 1]
13 node['data-language'] = lang if lang
14 node.content = node.css('.token-line').map(&:content).join("\n")
15 end
16
44 doc17 doc
45 end18 end
46 end19 end
lib/docs/filters/yarn/entries_berry.rb+2−17
@@ -2,26 +2,11 @@ module Docs · 1 unmodified line
2 class Yarn2 class Yarn
3 class EntriesBerryFilter < Docs::EntriesFilter3 class EntriesBerryFilter < Docs::EntriesFilter
4 def get_name4 def get_name
5 if slug.start_with?('configuration')5 at_css('main header h1').content
6 filename = at_css('main .active code')
7 content = filename.content
8 return filename.parent.content.sub content, " (#{content})"
9 end
10
11 name = at_css('h1').content
12
13 if slug.start_with?('getting-started')
14 active_link = at_css('main .active')
15 links = active_link.parent.children.to_a
16 name.prepend "#{links.index(active_link) + 1}. "
17 end
18
19 name
20 end6 end
21 7
22 def get_type8 def get_type
23 return 'CLI' if slug.start_with?('sdks', 'pnpify')9 at_css('nav.navbar a.navbar__item.navbar__link.navbar__link--active').content
24 at_css('header .active').content
25 end10 end
26 end11 end
27 end12 end
lib/docs/scrapers/yarn.rb+13−4
@@ -13,15 +13,16 @@ module Docs · 12 unmodified lines
13 HTML13 HTML
14 14
15 version 'Berry' do15 version 'Berry' do
16 self.release = '3.1.1'16 self.release = '4.5.1'
17 self.base_url = 'https://yarnpkg.com/'17 self.base_url = 'https://yarnpkg.com/'
18 self.links = {18 self.links = {
19 home: 'https://yarnpkg.com/',19 home: 'https://yarnpkg.com/',
20 code: 'https://github.com/yarnpkg/berry'20 code: 'https://github.com/yarnpkg/berry'
21 }21 }
22 html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry', 'title'22 self.root_path = 'getting-started'
23 options[:skip] = ['features', 'cli', 'configuration', 'advanced']23 html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry'
24 options[:skip_patterns] = [/\Aapi/, /\Apackage/]24 options[:skip] = ['cli', 'cli/builder', 'cli/pnpify', 'cli/sdks', 'protocols']
25 options[:skip_patterns] = [/\Aapi/, /\Ablog/, /\Apackage/, /\Aassets/]
25 end26 end
26 27
27 version 'Classic' do28 version 'Classic' do
@@ -38,5 +39,13 @@ module Docs · 10 unmodified lines
38 def get_latest_version(opts)39 def get_latest_version(opts)
39 get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/]40 get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/]
40 end41 end
42
43 private
44
45 # Some pages contain null bytes and cause the parser to fail
46 def parse(response)
47 response.body.gsub!(/[\x00\u0000\0]/, '')
48 super
49 end
41 end50 end
42end51end