Skip to content

Commit 13e629e

Browse files
authored
Merge pull request #2368 from ruiiiijiiiiang/feature/update-yarn-version
updated yarn version (3.1.1 > 4.5.1)
2 parents 4baf915 + d45d143 commit 13e629e

File tree

3 files changed

+34
-55
lines changed

3 files changed

+34
-55
lines changed

lib/docs/filters/yarn/clean_html_berry.rb

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,18 @@ module Docs
22
class Yarn
33
class CleanHtmlBerryFilter < Filter
44
def call
5-
if slug.empty?
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
5+
@doc = at_css('main .container div.theme-doc-markdown.markdown')
396

407
css('*').each do |node|
418
node.remove_attribute('style')
429
end
4310

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+
4417
doc
4518
end
4619
end

lib/docs/filters/yarn/entries_berry.rb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,11 @@ module Docs
22
class Yarn
33
class EntriesBerryFilter < Docs::EntriesFilter
44
def get_name
5-
if slug.start_with?('configuration')
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
5+
at_css('main header h1').content
206
end
217

228
def get_type
23-
return 'CLI' if slug.start_with?('sdks', 'pnpify')
24-
at_css('header .active').content
9+
at_css('nav.navbar a.navbar__item.navbar__link.navbar__link--active').content
2510
end
2611
end
2712
end

lib/docs/scrapers/yarn.rb

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,30 @@ class Yarn < UrlScraper
1212
Licensed under the BSD License.
1313
HTML
1414

15-
version 'Berry' do
16-
self.release = '3.1.1'
15+
version do
16+
self.release = '4.5.1'
1717
self.base_url = 'https://yarnpkg.com/'
1818
self.links = {
1919
home: 'https://yarnpkg.com/',
2020
code: 'https://github.com/yarnpkg/berry'
2121
}
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'
2236
html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry', 'title'
2337
options[:skip] = ['features', 'cli', 'configuration', 'advanced']
24-
options[:skip_patterns] = [/\Aapi/, /\Apackage/]
25-
end
38+
options[:skip_patterns] = [/\Aapi/, /\Apackage/] end
2639

2740
version 'Classic' do
2841
self.release = '1.22.17'
@@ -38,5 +51,13 @@ class Yarn < UrlScraper
3851
def get_latest_version(opts)
3952
get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/]
4053
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
4162
end
4263
end

0 commit comments

Comments
 (0)