History

Merge pull request #2368 from ruiiiijiiiiang/feature/update-yarn-version

updated yarn version (3.1.1 > 4.5.1)

Simon Legner committed 1 year ago

Commit 13e629e2 parents 4baf915 d45d1433 files · +34 −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 +25 −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+25−4
@@ -12,17 +12,30 @@ module Docs · 11 unmodified lines
12 Licensed under the BSD License.12 Licensed under the BSD License.
13 HTML13 HTML
14 14
15 version 'Berry' do15 version 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 self.root_path = 'getting-started'
23 html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry'
24 options[:skip] = ['cli', 'cli/builder', 'cli/pnpify', 'cli/sdks', 'protocols']
25 options[:skip_patterns] = [/\Aapi/, /\Ablog/, /\Apackage/, /\Aassets/]
26 end
27
28 version '3' do
29 self.release = '3.1.1'
30 self.base_url = 'https://v3.yarnpkg.com/'
31 self.links = {
32 home: 'https://v3.yarnpkg.com/',
33 code: 'https://github.com/yarnpkg/berry'
34 }
35 self.root_path = 'getting-started'
22 html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry', 'title'36 html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry', 'title'
23 options[:skip] = ['features', 'cli', 'configuration', 'advanced']37 options[:skip] = ['features', 'cli', 'configuration', 'advanced']
24 options[:skip_patterns] = [/\Aapi/, /\Apackage/]38 options[:skip_patterns] = [/\Aapi/, /\Apackage/] end
25 end
26 39
27 version 'Classic' do40 version 'Classic' do
28 self.release = '1.22.17'41 self.release = '1.22.17'
@@ -38,5 +51,13 @@ module Docs · 9 unmodified lines
38 def get_latest_version(opts)51 def get_latest_version(opts)
39 get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/]52 get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/]
40 end53 end
54
55 private
56
57 # Some pages contain null bytes and cause the parser to fail
58 def parse(response)
59 response.body.gsub!(/[\x00\u0000\0]/, '')
60 super
61 end
41 end62 end
42end63end