Fixes #1611. See #1655.
Unified · Split
| @@ -2,6 +2,11 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Mdn |
| 3 | 3 | class CompatTablesFilter < Filter |
| 4 | 4 | |
| 5 | + # Generate browser compatibility table | |
| 6 | + # Fixes "BCD tables only load in the browser" | |
| 7 | + # https://github.com/mdn/browser-compat-data | |
| 8 | + # https://github.com/mdn/yari/tree/main/client/src/document/ingredients/browser-compatibility-table | |
| 9 | + | |
| 5 | 10 | def call |
| 6 | 11 | if at_css('#browser_compatibility') \ |
| 7 | 12 | and not at_css('#browser_compatibility').next_sibling.classes.include?('warning') \ |
| @@ -33,6 +38,26 @@ module Docs · 25 unmodified lines | ||
| 33 | 38 | 'samsunginternet_android' => 'Samsung Internet' |
| 34 | 39 | } |
| 35 | 40 | |
| 41 | + def is_javascript | |
| 42 | + current_url.to_s.start_with?('https://developer.mozilla.org/en-US/docs/Web/JavaScript') | |
| 43 | + end | |
| 44 | + | |
| 45 | + def browsers | |
| 46 | + if is_javascript | |
| 47 | + {}.merge(BROWSERS).merge({'deno' => 'Deno', 'nodejs' => 'Node.js'}) | |
| 48 | + else | |
| 49 | + BROWSERS | |
| 50 | + end | |
| 51 | + end | |
| 52 | + | |
| 53 | + def browser_types | |
| 54 | + if is_javascript | |
| 55 | + {'Desktop'=>6, 'Mobile'=>6, 'Server'=>2,} | |
| 56 | + else | |
| 57 | + {'Desktop'=>6, 'Mobile'=>6,} | |
| 58 | + end | |
| 59 | + end | |
| 60 | + | |
| 36 | 61 | def generate_compatibility_table() |
| 37 | 62 | json_files_uri = request_bcd_uris() |
| 38 | 63 | |
| @@ -88,15 +113,15 @@ module Docs · 49 unmodified lines | ||
| 88 | 113 | |
| 89 | 114 | table.css('#bct-browser-type').each do |node| |
| 90 | 115 | node.add_child('<th>') |
| 91 | − %w(Desktop Mobile).each do |browser_type| | |
| 92 | − node.add_child("<th colspan=6>#{browser_type}") | |
| 116 | + browser_types.each do |browser_type, colspan| | |
| 117 | + node.add_child("<th colspan=#{colspan}>#{browser_type}") | |
| 93 | 118 | end |
| 94 | 119 | end |
| 95 | 120 | |
| 96 | 121 | table.css('#bct-browsers').each do |node| |
| 97 | 122 | node.add_child('<th>') |
| 98 | 123 | |
| 99 | − BROWSERS.values.each do |browser| | |
| 124 | + browsers.values.each do |browser| | |
| 100 | 125 | node.add_child("<th>#{browser}") |
| 101 | 126 | end |
| 102 | 127 | end |
| @@ -119,7 +144,7 @@ module Docs · 16 unmodified lines | ||
| 119 | 144 | end |
| 120 | 145 | |
| 121 | 146 | |
| 122 | − BROWSERS.keys.each do |browser_key| | |
| 147 | + browsers.keys.each do |browser_key| | |
| 123 | 148 | if key == '__compat' |
| 124 | 149 | add_data_to_entry(json['support'][browser_key], last_table_entry) |
| 125 | 150 | else |