From ad56aa406b0df49861d58e2dcdcb0c25e6499752 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Mon, 24 Apr 2023 12:05:37 +0200 Subject: [PATCH 1/2] MDN scrapers: fix browser compatibility table --- lib/docs/filters/mdn/compat_tables.rb | 47 +++++++++------------------ lib/docs/scrapers/mdn/mdn.rb | 3 +- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/lib/docs/filters/mdn/compat_tables.rb b/lib/docs/filters/mdn/compat_tables.rb index b9891db1..d51c8f2c 100644 --- a/lib/docs/filters/mdn/compat_tables.rb +++ b/lib/docs/filters/mdn/compat_tables.rb @@ -71,27 +71,14 @@ module Docs end def request_bcd_uris - url = current_url.to_s + '/index.json' - response = Request.run url - index_json = JSON.load response.body - - uris = [] - - index_json['doc']['body'].each do |element| - uris.push(element['value']['dataURL']) if element['type'] == 'browser_compatibility' and element['value']['dataURL'] - end - - uris.map! do |uri| - tmp_uri = URI.parse(base_url.to_s) - tmp_uri.path = uri - uri = tmp_uri.to_s - end - - return uris + hydration = JSON.load at_css('#hydration').text + files = hydration['doc']['browserCompat'] || [] + files.map { |file| "https://bcd.developer.mozilla.org/bcd/api/v0/current/#{file}.json" } end def generate_compatibility_table_wrapper(url) response = Request.run url + return "" unless response.success? @json_data = JSON.load(response.body)['data'] html_table = generate_basic_html_table() @@ -202,32 +189,30 @@ module Docs if version_removed[0] format_string = "" + elsif version_added[0] == 'No' + format_string = "" + elsif version_added[0] == '?' + format_string = "" else - if version_added[0] == 'No' - format_string = "" - elsif version_added[0] == '?' - format_string = "" - else - format_string = "" - end + format_string = "" end for value in (0..version_added.length-1) do if version_removed[value] - format_string += "
#{version_added[value]}-#{version_removed[value]}
" + version_string = "#{version_added[value]}–#{version_removed[value]}" else - if version_added[value] == 'No' - format_string += "
#{version_added[value]}
" - else - format_string += "
#{version_added[value]}
" - end + version_string = version_added[value] end if notes[value] - format_string += "
#{notes[value]}
" + format_string += "
#{version_string}#{notes[value]}
" + else + format_string += "
#{version_string}
" end end + format_string += "" + else format_string = "
?
" end diff --git a/lib/docs/scrapers/mdn/mdn.rb b/lib/docs/scrapers/mdn/mdn.rb index 00c43c3f..7ca01b05 100644 --- a/lib/docs/scrapers/mdn/mdn.rb +++ b/lib/docs/scrapers/mdn/mdn.rb @@ -7,7 +7,8 @@ module Docs code: 'https://github.com/mdn/content' } - html_filters.push 'mdn/clean_html', 'mdn/compat_tables' + html_filters.insert_before 'container', 'mdn/compat_tables' # needs access to