History

updated yarn version (3.1.1 > 4.5.1)

Rui Jiang committed 1 year ago

Commit 2216cb41 parent c7885d43 files · +22 −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 +13 −4
lib/docs/filters/yarn/clean_html_berry.rb+7−34
@@ -2,45 +2,18 @@ module Docs · 1 unmodified line
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+2−17
@@ -2,26 +2,11 @@ module Docs · 1 unmodified line
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+13−4
@@ -13,15 +13,16 @@ module Docs · 12 unmodified lines
1313 HTML
1414
1515 version 'Berry' do
16− self.release = '3.1.1'
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− html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry', 'title'
23− options[:skip] = ['features', 'cli', 'configuration', 'advanced']
24− options[:skip_patterns] = [/\Aapi/, /\Apackage/]
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/]
2526 end
2627
2728 version 'Classic' do
@@ -38,5 +39,13 @@ module Docs · 10 unmodified lines
3839 def get_latest_version(opts)
3940 get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/]
4041 end
42+
43+ private
44+
45+ # Some pages contain null bytes and cause the parser to fail
46+ def parse(response)
47+ response.body.gsub!(/[\x00\u0000\0]/, '')
48+ super
49+ end
4150 end
4251 end