History

Add Yarn berry

Kid committed 4 years ago

Commit f5dc6931 parent 72c0bbe4 files · +73 −17Browse files

Unified · Split

4 files
  1. lib/docs/filters/yarn/clean_html_berry.rb +26 −0
  2. lib/docs/filters/yarn/entries.rb +1 −5
  3. lib/docs/filters/yarn/entries_berry.rb +21 −0
  4. lib/docs/scrapers/yarn.rb +25 −12
lib/docs/filters/yarn/clean_html_berry.rb+26−0
@@ -0,0 +1,26 @@
1module Docs
2 class Yarn
3 class CleanHtmlBerryFilter < Filter
4 def call
5 # Version notice
6 css('#gatsby-focus-wrapper > div').remove
7
8 # Logo and menu
9 css('header > div:first-child').remove
10
11 # Left nav and TOC
12 css('main > div > div:first-child', 'aside').remove
13
14 # Title and edit link
15 css('article > div:first-child').remove
16
17 # Bottom divider on index
18 if slug == ''
19 css('main > hr').remove
20 end
21
22 doc
23 end
24 end
25 end
26end
lib/docs/filters/yarn/entries.rb+1−5
@@ -4,16 +4,12 @@ module Docs · 3 unmodified lines
4 def get_name4 def get_name
5 name = at_css('h1').content5 name = at_css('h1').content
6 6
7 unless type == 'CLI'
8 name.prepend "#{css('.guide-nav a').to_a.index(at_css('.guide-nav a.active')) + 1}. "
9 end
10
11 name7 name
12 end8 end
13 9
14 def get_type10 def get_type
15 type = at_css('.guide-nav a').content.strip11 type = at_css('.guide-nav a').content.strip
16 type.remove! ' Introduction'12 type.sub! 'CLI Introduction', 'CLI Commands'
17 type13 type
18 end14 end
19 end15 end
lib/docs/filters/yarn/entries_berry.rb+21−0
@@ -0,0 +1,21 @@
1module Docs
2 class Yarn
3 class EntriesBerryFilter < Docs::EntriesFilter
4 def get_name
5 name = at_css('h1').content
6
7 name
8 end
9
10 def get_type
11 if slug.start_with?('sdks') || slug.start_with?('pnpify')
12 'CLI'
13 else
14 type = at_css('header div:nth-child(2) .active').content.strip
15 type.remove! 'Home'
16 type
17 end
18 end
19 end
20 end
21end
lib/docs/scrapers/yarn.rb+25−12
@@ -1,28 +1,41 @@
1module Docs1module Docs
2 class Yarn < UrlScraper2 class Yarn < UrlScraper
3 self.type = 'simple'3 self.type = 'simple'
4 self.release = '1.22.17'
5 self.base_url = 'https://classic.yarnpkg.com/en/docs/'
6 self.links = {
7 home: 'https://classic.yarnpkg.com/',
8 code: 'https://github.com/yarnpkg/yarn'
9 }
10
11 html_filters.push 'yarn/entries', 'yarn/clean_html', 'title'
12 4
13 options[:root_title] = 'Yarn'5 options[:root_title] = 'Yarn'
14 options[:trailing_slash] = false6 options[:trailing_slash] = false
15 7
16 options[:skip] = %w(nightly)8 options[:skip] = %w(nightly)
17 options[:skip_patterns] = [/\Aorg\//]
18 9
19 options[:attribution] = <<-HTML10 options[:attribution] = <<-HTML
20 &copy; 2016&ndash;present Yarn Contributors<br>11 &copy; 2016&ndash;present Yarn Contributors<br>
21 Licensed under the BSD License.12 Licensed under the BSD License.
22 HTML13 HTML
23 14
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_patterns] = [/\Aapi/, /\Apackage/]
24 end
25
26 version 'Classic' do
27 self.release = '1.22.17'
28 self.base_url = 'https://classic.yarnpkg.com/en/docs/'
29 self.links = {
30 home: 'https://classic.yarnpkg.com/',
31 code: 'https://github.com/yarnpkg/yarn'
32 }
33 html_filters.push 'yarn/entries', 'yarn/clean_html', 'title'
34 options[:skip_patterns] = [/\Aorg\//]
35 end
36
24 def get_latest_version(opts)37 def get_latest_version(opts)
25 get_latest_github_release('yarnpkg', 'yarn', opts)38 get_latest_github_release('yarnpkg', 'berry', opts)
26 end39 end
27 end40 end
28end41end