Unified · Split
| @@ -2,45 +2,18 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Yarn |
| 3 | 3 | class CleanHtmlBerryFilter < Filter |
| 4 | 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 | |
| 5 | + @doc = at_css('main .container div.theme-doc-markdown.markdown') | |
| 39 | 6 | |
| 40 | 7 | css('*').each do |node| |
| 41 | 8 | node.remove_attribute('style') |
| 42 | 9 | end |
| 43 | 10 | |
| 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 | + | |
| 44 | 17 | doc |
| 45 | 18 | end |
| 46 | 19 | end |
| @@ -2,26 +2,11 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Yarn |
| 3 | 3 | class EntriesBerryFilter < Docs::EntriesFilter |
| 4 | 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 | |
| 5 | + at_css('main header h1').content | |
| 20 | 6 | end |
| 21 | 7 | |
| 22 | 8 | 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 | |
| 25 | 10 | end |
| 26 | 11 | end |
| 27 | 12 | end |
| @@ -13,15 +13,16 @@ module Docs · 12 unmodified lines | ||
| 13 | 13 | HTML |
| 14 | 14 | |
| 15 | 15 | version 'Berry' do |
| 16 | − self.release = '3.1.1' | |
| 16 | + self.release = '4.5.1' | |
| 17 | 17 | self.base_url = 'https://yarnpkg.com/' |
| 18 | 18 | self.links = { |
| 19 | 19 | home: 'https://yarnpkg.com/', |
| 20 | 20 | code: 'https://github.com/yarnpkg/berry' |
| 21 | 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/] | |
| 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/] | |
| 25 | 26 | end |
| 26 | 27 | |
| 27 | 28 | version 'Classic' do |
| @@ -38,5 +39,13 @@ module Docs · 10 unmodified lines | ||
| 38 | 39 | def get_latest_version(opts) |
| 39 | 40 | get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/] |
| 40 | 41 | 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 | |
| 41 | 50 | end |
| 42 | 51 | end |