Skip to content

Commit de58a63

Browse files
committed
Update Jest documentation (27.0.4)
1 parent 03c4c68 commit de58a63

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

assets/javascripts/templates/pages/about_tmpl.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ credits = [
408408
'https://raw.githubusercontent.com/jekyll/jekyll/master/LICENSE'
409409
], [
410410
'Jest',
411-
'2020 Facebook, Inc.',
411+
'2021 Facebook, Inc.',
412412
'MIT',
413413
'https://raw.githubusercontent.com/facebook/jest/master/LICENSE'
414414
], [

lib/docs/filters/jest/clean_html.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@ module Docs
22
class Jest
33
class CleanHtmlFilter < Filter
44
def call
5-
@doc = at_css('.mainContainer .post')
5+
@doc = at_css('article')
66

7-
at_css('h1').content = 'Jest' if root_page?
7+
at_css('h1').content = 'Jest Documentation' if root_page?
88

9-
css('.edit-page-link', '.hash-link', 'hr').remove
10-
11-
css('.postHeader', 'article', 'div:not([class])').each do |node|
12-
node.before(node.children).remove
13-
end
9+
css('hr', '.hash-link', 'button', '.badge').remove
1410

1511
css('.anchor').each do |node|
1612
node.parent['id'] = node['id']
1713
node.remove
1814
end
1915

20-
css('pre').each do |node|
16+
css('.prism-code').each do |node|
17+
node.name = 'pre'
2118
node['data-language'] = 'js'
2219
node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class']
20+
21+
counter = 0
22+
23+
node.css('.token-line').each do |subnode| # add newline each line of the code snippets
24+
if counter == 0
25+
else
26+
subnode.content = "\n#{subnode.content}"
27+
end
28+
29+
counter += 1
30+
end
31+
2332
node.content = node.content
2433
end
2534

lib/docs/filters/jest/entries.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,35 @@ module Docs
22
class Jest
33
class EntriesFilter < Docs::EntriesFilter
44
def get_name
5-
at_css('.mainContainer h1').content
5+
at_css('h1').content
66
end
77

88
def get_type
9-
type = at_css('.navListItemActive').ancestors('.navGroup').first.at_css('h3').content
9+
type = at_css('.menu__link--sublist.menu__link--active') # active sidebar element
10+
11+
if type.nil?
12+
type = 'API Reference'
13+
else
14+
type = type.content
15+
end
1016

1117
if type == 'Introduction'
1218
'Guides: Introduction'
1319
elsif type == 'API Reference'
14-
self.name
20+
name
1521
else
1622
type
1723
end
1824
end
1925

2026
def additional_entries
21-
return [] unless !root_page? && self.type == self.name # api page
22-
return [] if self.slug == 'environment-variables'
27+
return [] unless !root_page? && type == name # api page
28+
return [] if slug == 'environment-variables'
29+
return [] if slug == 'code-transformation'
2330

2431
entries = []
2532

26-
at_css('.mainContainer h2 + ul, ul.toc-headings').css('li > a').each do |node|
33+
css('h3').each do |node|
2734
code = node.at_css('code')
2835
next if code.nil?
2936

@@ -32,7 +39,7 @@ def additional_entries
3239
name.remove! %r{[\s=<].*}
3340
name.prepend 'jest ' if name.start_with?('--')
3441
name.prepend 'Config: ' if slug == 'configuration'
35-
id = node['href'].remove('#')
42+
id = node.at_css('.anchor')['id']
3643

3744
entries << [name, id]
3845
end

lib/docs/scrapers/jest.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
module Docs
22
class Jest < UrlScraper
3+
include MultipleBaseUrls
34
self.type = 'simple'
4-
self.release = '26.6'
5-
self.base_url = 'https://jestjs.io/docs/en/'
5+
self.release = '27.0.4'
6+
7+
self.base_urls = [
8+
'https://jestjs.io/docs/',
9+
'https://jestjs.io/docs/expect'
10+
]
11+
612
self.root_path = 'getting-started'
713
self.links = {
814
home: 'https://jestjs.io/',
@@ -11,10 +17,12 @@ class Jest < UrlScraper
1117

1218
html_filters.push 'jest/entries', 'jest/clean_html'
1319

14-
options[:container] = '.docMainWrapper'
20+
options[:skip_patterns] = [
21+
/\d*.x/ # avoid deprecated versions
22+
]
1523

1624
options[:attribution] = <<-HTML
17-
&copy; 2020 Facebook, Inc.<br>
25+
&copy; 2021 Facebook, Inc.<br>
1826
Licensed under the MIT License.
1927
HTML
2028

0 commit comments

Comments
 (0)