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 @@
1+module 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
26+end
lib/docs/filters/yarn/entries.rb+1−5
@@ -4,16 +4,12 @@ module Docs · 3 unmodified lines
44 def get_name
55 name = at_css('h1').content
66
7− unless type == 'CLI'
8− name.prepend "#{css('.guide-nav a').to_a.index(at_css('.guide-nav a.active')) + 1}. "
9− end
10−
117 name
128 end
139
1410 def get_type
1511 type = at_css('.guide-nav a').content.strip
16− type.remove! ' Introduction'
12+ type.sub! 'CLI Introduction', 'CLI Commands'
1713 type
1814 end
1915 end
lib/docs/filters/yarn/entries_berry.rb+21−0
@@ -0,0 +1,21 @@
1+module 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
21+end
lib/docs/scrapers/yarn.rb+25−12
@@ -1,28 +1,41 @@
11 module Docs
22 class Yarn < UrlScraper
33 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'
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
20− &copy; 2016&ndash;present Yarn Contributors<br>
21− Licensed under the BSD License.
11+ &copy; 2016&ndash;present Yarn Contributors<br>
12+ 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_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+
2437 def get_latest_version(opts)
25− get_latest_github_release('yarnpkg', 'yarn', opts)
38+ get_latest_github_release('yarnpkg', 'berry', opts)
2639 end
2740 end
2841 end