History

Fix some issues

Kid committed 4 years ago

Commit 7b48eed1 parent b39bebd3 files · +23 −12Browse files

Unified · Split

3 files
  1. lib/docs/filters/yarn/entries.rb +5 −2
  2. lib/docs/filters/yarn/entries_berry.rb +17 −10
  3. lib/docs/scrapers/yarn.rb +1 −0
lib/docs/filters/yarn/entries.rb+5−2
@@ -4,13 +4,16 @@ module Docs · 3 unmodified lines
44 def get_name
55 name = at_css('h1').content
66
7+ unless type == 'CLI'
8+ name.prepend "#{css('.guide-nav a').to_a.index(at_css('.guide-nav a.active')) + 1}. "
9+ end
10+
711 name
812 end
913
1014 def get_type
1115 type = at_css('.guide-nav a').content.strip
12− type.sub! 'CLI Introduction', 'CLI Commands'
13− type
16+ type.sub 'CLI Introduction', 'CLI Commands'
1417 end
1518 end
1619 end
lib/docs/filters/yarn/entries_berry.rb+17−10
@@ -2,24 +2,31 @@ module Docs · 1 unmodified line
22 class Yarn
33 class EntriesBerryFilter < Docs::EntriesFilter
44 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+
511 name = at_css('h1').content
612
7− # TODO: remove when https://github.com/yarnpkg/berry/issues/3809 is resolved
8− if slug.start_with?('sdks') || slug.start_with?('pnpify')
9− name.prepend('yarn ')
13+ if slug.start_with?('getting-started')
14+ name.remove! /\d - /
15+
16+ active_link = at_css('main .active')
17+ links = active_link.parent.children.to_a
18+ name.prepend "#{links.index(active_link) + 1}. "
1019 end
1120
21+ # TODO: remove when https://github.com/yarnpkg/berry/issues/3809 is resolved
22+ name.prepend('yarn ') if slug.start_with?('sdks', 'pnpify')
23+
1224 name
1325 end
1426
1527 def get_type
16− if slug.start_with?('sdks') || slug.start_with?('pnpify')
17− 'CLI'
18− else
19− type = at_css('header div:nth-child(2) .active').content.strip
20− type.remove! 'Home'
21− type
22− end
28+ return 'CLI' if slug.start_with?('sdks', 'pnpify')
29+ at_css('header .active').content
2330 end
2431 end
2532 end
lib/docs/scrapers/yarn.rb+1−0
@@ -20,6 +20,7 @@ module Docs · 19 unmodified lines
2020 code: 'https://github.com/yarnpkg/berry'
2121 }
2222 html_filters.push 'yarn/entries_berry', 'yarn/clean_html_berry', 'title'
23+ options[:skip] = ['features', 'cli', 'configuration', 'advanced']
2324 options[:skip_patterns] = [/\Aapi/, /\Apackage/]
2425 end
2526