@@ -5,38 +5,37 @@ class CompatTablesFilter < Filter
5
5
# Generate browser compatibility table
6
6
# Fixes "BCD tables only load in the browser"
7
7
# 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
9
9
10
10
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 ( )
22
12
23
13
doc
24
14
end
25
15
26
- BROWSERS = {
16
+ BROWSERS_DESKTOP = {
27
17
# Desktop
28
18
'chrome' => 'Chrome' ,
29
19
'edge' => 'Edge' ,
30
20
'firefox' => 'Firefox' ,
31
21
'opera' => 'Opera' ,
32
22
'safari' => 'Safari' ,
23
+ }
24
+ BROWSERS_MOBILE = {
33
25
# Mobile
34
26
'chrome_android' => 'Chrome Android' ,
35
27
'firefox_android' => 'Firefox for Android' ,
36
28
'opera_android' => 'Opera Android' ,
37
29
'safari_ios' => 'Safari on IOS' ,
38
30
'samsunginternet_android' => 'Samsung Internet' ,
39
31
'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' ,
40
39
}
41
40
42
41
def is_javascript
@@ -45,40 +44,28 @@ def is_javascript
45
44
46
45
def browsers
47
46
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 )
53
48
else
54
- BROWSERS
49
+ { } . merge ( BROWSERS_DESKTOP ) . merge ( BROWSERS_MOBILE )
55
50
end
56
51
end
57
52
58
53
def browser_types
59
54
if is_javascript
60
- { 'Desktop' => 5 , 'Mobile' => 6 , 'Server' => 2 , }
55
+ { 'Desktop' => BROWSERS_DESKTOP . length , 'Mobile' => BROWSERS_MOBILE . length , 'Server' => BROWSERS_SERVER . length , }
61
56
else
62
- { 'Desktop' => 5 , 'Mobile' => 6 , }
57
+ { 'Desktop' => BROWSERS_DESKTOP . length , 'Mobile' => BROWSERS_MOBILE . length , }
63
58
end
64
59
end
65
60
66
61
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 )
73
68
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" }
82
69
end
83
70
84
71
def generate_compatibility_table_wrapper ( url )
0 commit comments