Browse Source

Fix some issues

Kid 4 years ago
parent
commit
7b48eedcb1
3 changed files with 23 additions and 12 deletions
  1. 5 2
      lib/docs/filters/yarn/entries.rb
  2. 17 10
      lib/docs/filters/yarn/entries_berry.rb
  3. 1 0
      lib/docs/scrapers/yarn.rb

+ 5 - 2
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

+ 17 - 10
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

+ 1 - 0
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