Skip to content

Commit 6230041

Browse files
committed
Update JavaScript documentation
1 parent 7c4146b commit 6230041

File tree

4 files changed

+31
-52
lines changed

4 files changed

+31
-52
lines changed

lib/docs/filters/mdn/clean_html.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ class CleanHtmlFilter < Filter
1313
'.communitybox',
1414
'#Quick_Links',
1515
'aside.metadata',
16+
'.reference-layout__toc',
17+
'.article-footer',
1618
'hr']
1719

1820
BROWSER_UNNECESSARY_CLASS_REGEX = /\s*bc-browser[\w_-]+/
1921

2022
def call
2123
css(*REMOVE_NODES).remove
2224

25+
css('.reference-layout__header', '.reference-layout__body').each do |node|
26+
node.before(node.children).remove
27+
end
28+
2329
css('td.header').each do |node|
2430
node.name = 'th'
2531
end

lib/docs/filters/mdn/compat_tables.rb

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,37 @@ class CompatTablesFilter < Filter
55
# Generate browser compatibility table
66
# Fixes "BCD tables only load in the browser"
77
# https://github.com/mdn/browser-compat-data
8-
# https://github.com/mdn/yari/tree/main/client/src/document/ingredients/browser-compatibility-table
8+
# https://github.com/mdn/yari/tree/main/client/src/lit/compat
99

1010
def call
11-
if at_css('#browser_compatibility') \
12-
and not at_css('#browser_compatibility').next_sibling.classes.include?('warning') \
13-
and not at_css('#browser_compatibility').next_sibling.content.match?('Supported')
14-
15-
at_css('#browser_compatibility').next_sibling.remove
16-
17-
compatibility_tables = generate_compatibility_table()
18-
compatibility_tables.each do |table|
19-
at_css('#browser_compatibility').add_next_sibling(table)
20-
end
21-
end
11+
generate_compatibility_table()
2212

2313
doc
2414
end
2515

26-
BROWSERS = {
16+
BROWSERS_DESKTOP = {
2717
# Desktop
2818
'chrome' => 'Chrome',
2919
'edge' => 'Edge',
3020
'firefox' => 'Firefox',
3121
'opera' => 'Opera',
3222
'safari' => 'Safari',
23+
}
24+
BROWSERS_MOBILE = {
3325
# Mobile
3426
'chrome_android' => 'Chrome Android',
3527
'firefox_android' => 'Firefox for Android',
3628
'opera_android' => 'Opera Android',
3729
'safari_ios' => 'Safari on IOS',
3830
'samsunginternet_android' => 'Samsung Internet',
3931
'webview_android' => 'WebView Android',
32+
'webview_ios' => 'WebView on iOS',
33+
}
34+
BROWSERS_SERVER = {
35+
# Server
36+
'bun' => 'Bun',
37+
'deno' => 'Deno',
38+
'nodejs' => 'Node.js',
4039
}
4140

4241
def is_javascript
@@ -45,40 +44,28 @@ def is_javascript
4544

4645
def browsers
4746
if is_javascript
48-
{}.merge(BROWSERS).merge({
49-
# Server
50-
'deno' => 'Deno',
51-
'nodejs' => 'Node.js',
52-
})
47+
{}.merge(BROWSERS_DESKTOP).merge(BROWSERS_MOBILE).merge(BROWSERS_SERVER)
5348
else
54-
BROWSERS
49+
{}.merge(BROWSERS_DESKTOP).merge(BROWSERS_MOBILE)
5550
end
5651
end
5752

5853
def browser_types
5954
if is_javascript
60-
{'Desktop'=>5, 'Mobile'=>6, 'Server'=>2,}
55+
{'Desktop'=>BROWSERS_DESKTOP.length, 'Mobile'=>BROWSERS_MOBILE.length, 'Server'=>BROWSERS_SERVER.length,}
6156
else
62-
{'Desktop'=>5, 'Mobile'=>6,}
57+
{'Desktop'=>BROWSERS_DESKTOP.length, 'Mobile'=>BROWSERS_MOBILE.length,}
6358
end
6459
end
6560

6661
def generate_compatibility_table()
67-
json_files_uri = request_bcd_uris()
68-
69-
compat_tables = []
70-
71-
json_files_uri.each do |uri|
72-
compat_tables.push(generate_compatibility_table_wrapper(uri))
62+
css('mdn-compat-table-lazy').each do |node|
63+
file = node.attr('query')
64+
# https://github.com/mdn/browser-compat-data/blob/main/javascript/builtins/Set.json
65+
# https://bcd.developer.mozilla.org/bcd/api/v0/current/javascript.builtins.Set.json
66+
uri = "https://bcd.developer.mozilla.org/bcd/api/v0/current/#{file}.json"
67+
node.replace generate_compatibility_table_wrapper(uri)
7368
end
74-
75-
return compat_tables
76-
end
77-
78-
def request_bcd_uris
79-
hydration = JSON.load at_css('#hydration').text
80-
files = hydration['doc']['browserCompat'] || []
81-
files.map { |file| "https://bcd.developer.mozilla.org/bcd/api/v0/current/#{file}.json" }
8269
end
8370

8471
def generate_compatibility_table_wrapper(url)

lib/docs/scrapers/mdn/javascript.rb

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Javascript < Mdn
33
prepend FixInternalUrlsBehavior
44
prepend FixRedirectionsBehavior
55

6-
# release = '2025-06-01'
6+
# release = '2025-09-15'
77
self.name = 'JavaScript'
88
self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference'
99
self.links = {
@@ -22,25 +22,11 @@ class Javascript < Mdn
2222
/Statements)
2323

2424
options[:skip_patterns] = [
25-
/additional_examples/i,
26-
/noSuchMethod/i,
25+
/contributors.txt/,
2726
/Deprecated_and_obsolete_features/
2827
]
2928

30-
options[:replace_paths] = {
31-
'/template_strings' => '/Template_literals',
32-
'/Functions_and_function_scope/Strict_mode' => '/Strict_mode'
33-
}
34-
3529
options[:fix_urls] = ->(url) do
36-
url.sub! 'https://developer.mozilla.org/en-US/docs/JavaScript/Reference', Javascript.base_url
37-
url.sub! 'https://developer.mozilla.org/en/JavaScript/Reference', Javascript.base_url
38-
url.sub! 'https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference', Javascript.base_url
39-
url.sub! 'https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference', Javascript.base_url
40-
url.sub! '/Operators/Special/', '/Operators/'
41-
url.sub! 'Destructing_assignment', 'Destructuring_assignment'
42-
url.sub! '/Functions_and_function_scope', '/Functions'
43-
url.sub! 'Array.prototype.values()', 'values'
4430
url.sub! '%2A', '*'
4531
url.sub! '%40', '@'
4632
url

lib/docs/scrapers/mdn/mdn.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Mdn < UrlScraper
1010
html_filters.insert_before 'container', 'mdn/compat_tables' # needs access to <script type="application/json" id="hydration">
1111
html_filters.push 'mdn/clean_html'
1212

13-
options[:container] = '#content > .main-page-content'
13+
options[:container] = '#content'
1414
options[:trailing_slash] = false
1515

1616
options[:skip_link] = ->(link) {

0 commit comments

Comments
 (0)