[devdocsgjs/main: 18/239] Add Yarn berry




commit f5dc69391b2ddef71af58a1a562feb11a824941d
Author: Kid <44045911+kidonng users noreply github com>
Date:   Sun Nov 28 08:24:55 2021 +0000

    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(-)
---
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
-      &copy; 2016&ndash;present Yarn Contributors<br>
-      Licensed under the BSD License.
+    &copy; 2016&ndash;present Yarn Contributors<br>
+    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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]