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..96b3ee53 --- /dev/null +++ b/lib/docs/filters/yarn/clean_html_berry.rb @@ -0,0 +1,48 @@ +module Docs + class Yarn + class CleanHtmlBerryFilter < Filter + def call + if slug.empty? + @doc = at_css('main') + css( + (['div:first-child'] * 3).join('>'), # Tagline + 'img', + 'hr', # Footer + 'hr + div', # Footer + ).remove + + css('a').each do |link| + link.name = 'div' + link.css('h3').each do |node| + node.replace("

#{node.content}

") + end + end + + return doc + end + + @doc = at_css('article') + # Heading & edit link + css('h1', 'h1 + a').remove unless slug.start_with?('configuration') + + if slug.start_with?('cli') + css('.header-code').each do |node| + node.name = 'span' + end + end + + if slug.start_with?('configuration') + css('h1', 'h2').each do |node| + node.name = node.name.sub(/\d/) { |i| i.to_i + 1 } + end + end + + css('*').each do |node| + node.remove_attribute('style') + end + + doc + end + end + end +end diff --git a/lib/docs/filters/yarn/entries.rb b/lib/docs/filters/yarn/entries.rb index 809bb1a6..ebd65838 100644 --- a/lib/docs/filters/yarn/entries.rb +++ b/lib/docs/filters/yarn/entries.rb @@ -13,8 +13,7 @@ module Docs def get_type type = at_css('.guide-nav a').content.strip - type.remove! ' Introduction' - type + type.sub 'CLI Introduction', 'CLI Commands' end 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..44c1e18e --- /dev/null +++ b/lib/docs/filters/yarn/entries_berry.rb @@ -0,0 +1,28 @@ +module Docs + class Yarn + class EntriesBerryFilter < Docs::EntriesFilter + def get_name + if slug.start_with?('configuration') + filename = at_css('main .active code') + content = filename.content + return filename.parent.content.sub content, " (#{content})" + end + + name = at_css('h1').content + + if slug.start_with?('getting-started') + active_link = at_css('main .active') + links = active_link.parent.children.to_a + name.prepend "#{links.index(active_link) + 1}. " + end + + name + end + + def get_type + return 'CLI' if slug.start_with?('sdks', 'pnpify') + at_css('header .active').content + end + end + end +end diff --git a/lib/docs/scrapers/yarn.rb b/lib/docs/scrapers/yarn.rb index 64c32180..8cc49260 100644 --- a/lib/docs/scrapers/yarn.rb +++ b/lib/docs/scrapers/yarn.rb @@ -1,28 +1,42 @@ module Docs class Yarn < UrlScraper self.type = 'simple' - self.release = '1.19.0' - self.base_url = 'https://yarnpkg.com/en/docs/' - self.links = { - home: 'https://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. 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] = ['features', 'cli', 'configuration', 'advanced'] + 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)[/[\d.]+/] end end end