diff --git a/lib/docs/filters/yarn/clean_html_berry.rb b/lib/docs/filters/yarn/clean_html_berry.rb new file mode 100644 index 00000000..00e0316c --- /dev/null +++ b/lib/docs/filters/yarn/clean_html_berry.rb @@ -0,0 +1,26 @@ +module Docs + class Yarn + class CleanHtmlBerryFilter < Filter + def call + # Version notice + css('#gatsby-focus-wrapper > div').remove + + # Logo and menu + css('header > div:first-child').remove + + # Left nav and TOC + css('main > div > div:first-child', 'aside').remove + + # Title and edit link + css('article > div:first-child').remove + + # Bottom divider on index + if slug == '' + css('main > hr').remove + end + + doc + end + end + end +end diff --git a/lib/docs/filters/yarn/entries.rb b/lib/docs/filters/yarn/entries.rb index 809bb1a6..8e242723 100644 --- a/lib/docs/filters/yarn/entries.rb +++ b/lib/docs/filters/yarn/entries.rb @@ -4,16 +4,12 @@ module Docs def get_name name = at_css('h1').content - unless type == 'CLI' - name.prepend "#{css('.guide-nav a').to_a.index(at_css('.guide-nav a.active')) + 1}. " - end - name end def get_type type = at_css('.guide-nav a').content.strip - type.remove! ' Introduction' + type.sub! 'CLI Introduction', 'CLI Commands' type end end diff --git a/lib/docs/filters/yarn/entries_berry.rb b/lib/docs/filters/yarn/entries_berry.rb new file mode 100644 index 00000000..b9a74e96 --- /dev/null +++ b/lib/docs/filters/yarn/entries_berry.rb @@ -0,0 +1,21 @@ +module Docs + class Yarn + class EntriesBerryFilter < Docs::EntriesFilter + def get_name + name = at_css('h1').content + + name + end + + def get_type + if slug.start_with?('sdks') || slug.start_with?('pnpify') + 'CLI' + else + type = at_css('header div:nth-child(2) .active').content.strip + type.remove! 'Home' + type + end + end + end + end +end diff --git a/lib/docs/scrapers/yarn.rb b/lib/docs/scrapers/yarn.rb index 1f6a192b..9ce03a51 100644 --- a/lib/docs/scrapers/yarn.rb +++ b/lib/docs/scrapers/yarn.rb @@ -1,28 +1,41 @@ module Docs class Yarn < UrlScraper self.type = 'simple' - self.release = '1.22.17' - self.base_url = 'https://classic.yarnpkg.com/en/docs/' - self.links = { - home: 'https://classic.yarnpkg.com/', - code: 'https://github.com/yarnpkg/yarn' - } - - html_filters.push 'yarn/entries', 'yarn/clean_html', 'title' options[:root_title] = 'Yarn' options[:trailing_slash] = false options[:skip] = %w(nightly) - options[:skip_patterns] = [/\Aorg\//] options[:attribution] = <<-HTML - © 2016–present Yarn Contributors
- Licensed under the BSD License. + © 2016–present Yarn Contributors
+ Licensed under the BSD License. HTML + version 'Berry' do + self.release = '3.1.1' + self.base_url = 'https://yarnpkg.com/' + self.links = { + home: 'https://yarnpkg.com/', + code: 'https://github.com/yarnpkg/berry' + } + html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry', 'title' + options[:skip_patterns] = [/\Aapi/, /\Apackage/] + end + + version 'Classic' do + self.release = '1.22.17' + self.base_url = 'https://classic.yarnpkg.com/en/docs/' + self.links = { + home: 'https://classic.yarnpkg.com/', + code: 'https://github.com/yarnpkg/yarn' + } + html_filters.push 'yarn/entries', 'yarn/clean_html', 'title' + options[:skip_patterns] = [/\Aorg\//] + end + def get_latest_version(opts) - get_latest_github_release('yarnpkg', 'yarn', opts) + get_latest_github_release('yarnpkg', 'berry', opts) end end end