@@ -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 )
0 commit comments