Skip to content

Commit ae91426

Browse files
authored
Merge pull request #1667 from kidonng/patch-1
yarn: update to 1.22.17 and add Yarn berry
2 parents 049f7dd + 07279d6 commit ae91426

File tree

4 files changed

+101
-12
lines changed

4 files changed

+101
-12
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module Docs
2+
class Yarn
3+
class CleanHtmlBerryFilter < Filter
4+
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
39+
40+
css('*').each do |node|
41+
node.remove_attribute('style')
42+
end
43+
44+
doc
45+
end
46+
end
47+
end
48+
end

lib/docs/filters/yarn/entries.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ def get_name
1313

1414
def get_type
1515
type = at_css('.guide-nav a').content.strip
16-
type.remove! ' Introduction'
17-
type
16+
type.sub 'CLI Introduction', 'CLI Commands'
1817
end
1918
end
2019
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Docs
2+
class Yarn
3+
class EntriesBerryFilter < Docs::EntriesFilter
4+
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
20+
end
21+
22+
def get_type
23+
return 'CLI' if slug.start_with?('sdks', 'pnpify')
24+
at_css('header .active').content
25+
end
26+
end
27+
end
28+
end

lib/docs/scrapers/yarn.rb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
module Docs
22
class Yarn < UrlScraper
33
self.type = 'simple'
4-
self.release = '1.19.0'
5-
self.base_url = 'https://yarnpkg.com/en/docs/'
6-
self.links = {
7-
home: 'https://yarnpkg.com/',
8-
code: 'https://github.com/yarnpkg/yarn'
9-
}
10-
11-
html_filters.push 'yarn/entries', 'yarn/clean_html', 'title'
124

135
options[:root_title] = 'Yarn'
146
options[:trailing_slash] = false
157

168
options[:skip] = %w(nightly)
17-
options[:skip_patterns] = [/\Aorg\//]
189

1910
options[:attribution] = <<-HTML
2011
&copy; 2016&ndash;present Yarn Contributors<br>
2112
Licensed under the BSD License.
2213
HTML
2314

15+
version 'Berry' do
16+
self.release = '3.1.1'
17+
self.base_url = 'https://yarnpkg.com/'
18+
self.links = {
19+
home: 'https://yarnpkg.com/',
20+
code: 'https://github.com/yarnpkg/berry'
21+
}
22+
html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry', 'title'
23+
options[:skip] = ['features', 'cli', 'configuration', 'advanced']
24+
options[:skip_patterns] = [/\Aapi/, /\Apackage/]
25+
end
26+
27+
version 'Classic' do
28+
self.release = '1.22.17'
29+
self.base_url = 'https://classic.yarnpkg.com/en/docs/'
30+
self.links = {
31+
home: 'https://classic.yarnpkg.com/',
32+
code: 'https://github.com/yarnpkg/yarn'
33+
}
34+
html_filters.push 'yarn/entries', 'yarn/clean_html', 'title'
35+
options[:skip_patterns] = [/\Aorg\//]
36+
end
37+
2438
def get_latest_version(opts)
25-
get_latest_github_release('yarnpkg', 'yarn', opts)
39+
get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/]
2640
end
2741
end
2842
end

0 commit comments

Comments
 (0)