Unified · Split
| @@ -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 | ||
| @@ -13,8 +13,7 @@ module Docs · 12 unmodified lines | |||
| 13 | 13 | ||
| 14 | def get_type | 14 | def get_type |
| 15 | type = at_css('.guide-nav a').content.strip | 15 | type = at_css('.guide-nav a').content.strip |
| 16 | type.remove! ' Introduction' | 16 | type.sub 'CLI Introduction', 'CLI Commands' |
| 17 | type | ||
| 18 | end | 17 | end |
| 19 | end | 18 | end |
| 20 | end | 19 | end |
| @@ -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 | ||
| @@ -1,28 +1,42 @@ | |||
| 1 | module Docs | 1 | module Docs |
| 2 | class Yarn < UrlScraper | 2 | class Yarn < UrlScraper |
| 3 | self.type = 'simple' | 3 | 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' | ||
| 12 | 4 | ||
| 13 | options[:root_title] = 'Yarn' | 5 | options[:root_title] = 'Yarn' |
| 14 | options[:trailing_slash] = false | 6 | 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] = <<-HTML | 10 | options[:attribution] = <<-HTML |
| 20 | © 2016–present Yarn Contributors<br> | 11 | © 2016–present Yarn Contributors<br> |
| 21 | Licensed under the BSD License. | 12 | Licensed under the BSD License. |
| 22 | HTML | 13 | 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] = ['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 | |||
| 24 | def get_latest_version(opts) | 38 | def get_latest_version(opts) |
| 25 | get_latest_github_release('yarnpkg', 'yarn', opts) | 39 | get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/] |
| 26 | end | 40 | end |
| 27 | end | 41 | end |
| 28 | end | 42 | end |