diff --git a/lib/docs/filters/mdn/compat_tables.rb b/lib/docs/filters/mdn/compat_tables.rb index 13695b9e..285a26b0 100644 --- a/lib/docs/filters/mdn/compat_tables.rb +++ b/lib/docs/filters/mdn/compat_tables.rb @@ -2,6 +2,11 @@ module Docs class Mdn class CompatTablesFilter < Filter + # Generate browser compatibility table + # Fixes "BCD tables only load in the browser" + # https://github.com/mdn/browser-compat-data + # https://github.com/mdn/yari/tree/main/client/src/document/ingredients/browser-compatibility-table + def call if at_css('#browser_compatibility') \ and not at_css('#browser_compatibility').next_sibling.classes.include?('warning') \ @@ -33,6 +38,26 @@ module Docs 'samsunginternet_android' => 'Samsung Internet' } + def is_javascript + current_url.to_s.start_with?('https://developer.mozilla.org/en-US/docs/Web/JavaScript') + end + + def browsers + if is_javascript + {}.merge(BROWSERS).merge({'deno' => 'Deno', 'nodejs' => 'Node.js'}) + else + BROWSERS + end + end + + def browser_types + if is_javascript + {'Desktop'=>6, 'Mobile'=>6, 'Server'=>2,} + else + {'Desktop'=>6, 'Mobile'=>6,} + end + end + def generate_compatibility_table() json_files_uri = request_bcd_uris() @@ -88,15 +113,15 @@ module Docs table.css('#bct-browser-type').each do |node| node.add_child('