From 72c0bbe936c0ebceb86b15f5890cb7faf69cd8bb Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Sun, 28 Nov 2021 13:49:49 +0800 Subject: [PATCH 01/10] yarn: update to 1.22.17 --- lib/docs/scrapers/yarn.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/docs/scrapers/yarn.rb b/lib/docs/scrapers/yarn.rb index 64c32180..1f6a192b 100644 --- a/lib/docs/scrapers/yarn.rb +++ b/lib/docs/scrapers/yarn.rb @@ -1,10 +1,10 @@ module Docs class Yarn < UrlScraper self.type = 'simple' - self.release = '1.19.0' - self.base_url = 'https://yarnpkg.com/en/docs/' + self.release = '1.22.17' + self.base_url = 'https://classic.yarnpkg.com/en/docs/' self.links = { - home: 'https://yarnpkg.com/', + home: 'https://classic.yarnpkg.com/', code: 'https://github.com/yarnpkg/yarn' } From f5dc69391b2ddef71af58a1a562feb11a824941d Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Sun, 28 Nov 2021 08:24:55 +0000 Subject: [PATCH 02/10] Add Yarn berry --- lib/docs/filters/yarn/clean_html_berry.rb | 26 ++++++++++++++++ lib/docs/filters/yarn/entries.rb | 6 +--- lib/docs/filters/yarn/entries_berry.rb | 21 +++++++++++++ lib/docs/scrapers/yarn.rb | 37 +++++++++++++++-------- 4 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 lib/docs/filters/yarn/clean_html_berry.rb create mode 100644 lib/docs/filters/yarn/entries_berry.rb 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 From b39bebd27a87ec96d28a91d39837e747182f2044 Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Sun, 28 Nov 2021 08:55:51 +0000 Subject: [PATCH 03/10] Add missing command prefixes --- lib/docs/filters/yarn/entries_berry.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/docs/filters/yarn/entries_berry.rb b/lib/docs/filters/yarn/entries_berry.rb index b9a74e96..d70608af 100644 --- a/lib/docs/filters/yarn/entries_berry.rb +++ b/lib/docs/filters/yarn/entries_berry.rb @@ -4,6 +4,11 @@ module Docs def get_name name = at_css('h1').content + # TODO: remove when https://github.com/yarnpkg/berry/issues/3809 is resolved + if slug.start_with?('sdks') || slug.start_with?('pnpify') + name.prepend('yarn ') + end + name end From 7b48eedcb1d889222ce594eb8bb774ee1d9957a7 Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Mon, 29 Nov 2021 03:12:14 +0000 Subject: [PATCH 04/10] Fix some issues --- lib/docs/filters/yarn/entries.rb | 7 +++++-- lib/docs/filters/yarn/entries_berry.rb | 27 ++++++++++++++++---------- lib/docs/scrapers/yarn.rb | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/docs/filters/yarn/entries.rb b/lib/docs/filters/yarn/entries.rb index 8e242723..ebd65838 100644 --- a/lib/docs/filters/yarn/entries.rb +++ b/lib/docs/filters/yarn/entries.rb @@ -4,13 +4,16 @@ 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.sub! 'CLI Introduction', 'CLI Commands' - 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 index d70608af..da6a9ea5 100644 --- a/lib/docs/filters/yarn/entries_berry.rb +++ b/lib/docs/filters/yarn/entries_berry.rb @@ -2,24 +2,31 @@ 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 - # TODO: remove when https://github.com/yarnpkg/berry/issues/3809 is resolved - if slug.start_with?('sdks') || slug.start_with?('pnpify') - name.prepend('yarn ') + if slug.start_with?('getting-started') + name.remove! /\d - / + + active_link = at_css('main .active') + links = active_link.parent.children.to_a + name.prepend "#{links.index(active_link) + 1}. " end + # TODO: remove when https://github.com/yarnpkg/berry/issues/3809 is resolved + name.prepend('yarn ') if slug.start_with?('sdks', 'pnpify') + 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 + return 'CLI' if slug.start_with?('sdks', 'pnpify') + at_css('header .active').content end end end diff --git a/lib/docs/scrapers/yarn.rb b/lib/docs/scrapers/yarn.rb index 9ce03a51..90a2a1c7 100644 --- a/lib/docs/scrapers/yarn.rb +++ b/lib/docs/scrapers/yarn.rb @@ -20,6 +20,7 @@ module Docs 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 From 19d6edf65b317081ee6b51d39bd6f456d362d455 Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Mon, 29 Nov 2021 03:14:02 +0000 Subject: [PATCH 05/10] Fix format --- lib/docs/scrapers/yarn.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/docs/scrapers/yarn.rb b/lib/docs/scrapers/yarn.rb index 90a2a1c7..12b44f5e 100644 --- a/lib/docs/scrapers/yarn.rb +++ b/lib/docs/scrapers/yarn.rb @@ -8,8 +8,8 @@ module Docs options[:skip] = %w(nightly) 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 From e17bbbf23ce3768cf9eb7991830a8c0bcbc752b3 Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Mon, 29 Nov 2021 03:43:16 +0000 Subject: [PATCH 06/10] Clean more elements --- lib/docs/filters/yarn/clean_html_berry.rb | 41 +++++++++++++++++------ 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/docs/filters/yarn/clean_html_berry.rb b/lib/docs/filters/yarn/clean_html_berry.rb index 00e0316c..5d901150 100644 --- a/lib/docs/filters/yarn/clean_html_berry.rb +++ b/lib/docs/filters/yarn/clean_html_berry.rb @@ -2,21 +2,40 @@ module Docs class Yarn class CleanHtmlBerryFilter < Filter def call - # Version notice - css('#gatsby-focus-wrapper > div').remove + if slug.empty? + @doc = at_css('main') + css( + (['div:first-child'] * 3).join('>'), # Tagline + 'img', + 'hr', # Footer + 'hr + div', # Footer + ).remove - # Logo and menu - css('header > div:first-child').remove + css('a').each do |link| + link.name = 'div' + link.css('h3').each do |node| + node.replace("

#{node.content}

") + end + end - # Left nav and TOC - css('main > div > div:first-child', 'aside').remove + return doc + end + + @doc = at_css('article') + # Heading & edit link + css('h1', 'h1 + a').remove unless slug.start_with?('configuration') - # Title and edit link - css('article > div:first-child').remove + if slug.start_with?('cli') + css('.header-code').each do |node| + node.name = 'span' + end + end - # Bottom divider on index - if slug == '' - css('main > hr').remove + if slug.start_with?('configuration') + css('h1', 'h2').each do |node| + node.name = node.name.sub(/\d/) { |i| i.to_i + 1 } + node.remove_attribute('style') + end end doc From 98b46e6d59bddf2e11747b99c7daa22b9ef3391c Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Tue, 30 Nov 2021 04:56:48 +0800 Subject: [PATCH 07/10] Remove unnecessary prefix --- lib/docs/filters/yarn/entries_berry.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/docs/filters/yarn/entries_berry.rb b/lib/docs/filters/yarn/entries_berry.rb index da6a9ea5..d02d9f83 100644 --- a/lib/docs/filters/yarn/entries_berry.rb +++ b/lib/docs/filters/yarn/entries_berry.rb @@ -18,9 +18,6 @@ module Docs name.prepend "#{links.index(active_link) + 1}. " end - # TODO: remove when https://github.com/yarnpkg/berry/issues/3809 is resolved - name.prepend('yarn ') if slug.start_with?('sdks', 'pnpify') - name end From c5dbdbd1cff507f3aaa7b0e639049203ed5c51df Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Thu, 2 Dec 2021 08:10:20 +0800 Subject: [PATCH 08/10] Remove outdated clenaup --- lib/docs/filters/yarn/entries_berry.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/docs/filters/yarn/entries_berry.rb b/lib/docs/filters/yarn/entries_berry.rb index d02d9f83..44c1e18e 100644 --- a/lib/docs/filters/yarn/entries_berry.rb +++ b/lib/docs/filters/yarn/entries_berry.rb @@ -11,8 +11,6 @@ module Docs name = at_css('h1').content if slug.start_with?('getting-started') - name.remove! /\d - / - active_link = at_css('main .active') links = active_link.parent.children.to_a name.prepend "#{links.index(active_link) + 1}. " From e16232728ef21780108a682b8168f5703e7c5119 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Thu, 2 Dec 2021 22:42:09 +0100 Subject: [PATCH 09/10] yarn: fix get_latest_version --- lib/docs/scrapers/yarn.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/docs/scrapers/yarn.rb b/lib/docs/scrapers/yarn.rb index 12b44f5e..8cc49260 100644 --- a/lib/docs/scrapers/yarn.rb +++ b/lib/docs/scrapers/yarn.rb @@ -36,7 +36,7 @@ module Docs end def get_latest_version(opts) - get_latest_github_release('yarnpkg', 'berry', opts) + get_latest_github_release('yarnpkg', 'berry', opts)[/[\d.]+/] end end end From 07279d6aaeb06e685bf09198247b7066e4ac69e3 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Thu, 2 Dec 2021 22:42:15 +0100 Subject: [PATCH 10/10] yarn: clean all styles --- lib/docs/filters/yarn/clean_html_berry.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/docs/filters/yarn/clean_html_berry.rb b/lib/docs/filters/yarn/clean_html_berry.rb index 5d901150..96b3ee53 100644 --- a/lib/docs/filters/yarn/clean_html_berry.rb +++ b/lib/docs/filters/yarn/clean_html_berry.rb @@ -34,10 +34,13 @@ module Docs if slug.start_with?('configuration') css('h1', 'h2').each do |node| node.name = node.name.sub(/\d/) { |i| i.to_i + 1 } - node.remove_attribute('style') end end + css('*').each do |node| + node.remove_attribute('style') + end + doc end end