MDN scrapers: fix browser compatibility table

pull/1972/head
Simon Legner 2 years ago
parent 6febd56d4d
commit ad56aa406b

@ -71,27 +71,14 @@ module Docs
end end
def request_bcd_uris def request_bcd_uris
url = current_url.to_s + '/index.json' hydration = JSON.load at_css('#hydration').text
response = Request.run url files = hydration['doc']['browserCompat'] || []
index_json = JSON.load response.body files.map { |file| "https://bcd.developer.mozilla.org/bcd/api/v0/current/#{file}.json" }
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
end end
def generate_compatibility_table_wrapper(url) def generate_compatibility_table_wrapper(url)
response = Request.run url response = Request.run url
return "" unless response.success?
@json_data = JSON.load(response.body)['data'] @json_data = JSON.load(response.body)['data']
html_table = generate_basic_html_table() html_table = generate_basic_html_table()
@ -202,32 +189,30 @@ module Docs
if version_removed[0] if version_removed[0]
format_string = "<td class=bc-supports-no>" format_string = "<td class=bc-supports-no>"
elsif version_added[0] == 'No'
format_string = "<td class=bc-supports-no>"
elsif version_added[0] == '?'
format_string = "<td class=bc-supports-unknown>"
else else
if version_added[0] == 'No' format_string = "<td class=bc-supports-yes>"
format_string = "<td class=bc-supports-no>"
elsif version_added[0] == '?'
format_string = "<td class=bc-supports-unknown>"
else
format_string = "<td class=bc-supports-yes>"
end
end end
for value in (0..version_added.length-1) do for value in (0..version_added.length-1) do
if version_removed[value] if version_removed[value]
format_string += "<div>#{version_added[value]}-#{version_removed[value]}</div>" version_string = "#{version_added[value]}#{version_removed[value]}"
else else
if version_added[value] == 'No' version_string = version_added[value]
format_string += "<div>#{version_added[value]}</div>"
else
format_string += "<div>#{version_added[value]}</div>"
end
end end
if notes[value] if notes[value]
format_string += "<div>#{notes[value]}</div>" format_string += "<details><summary>#{version_string}</summary>#{notes[value]}</details>"
else
format_string += "<div>#{version_string}</div>"
end end
end end
format_string += "</td>"
else else
format_string = "<td class=bc-supports-unknown><div>?</div></td>" format_string = "<td class=bc-supports-unknown><div>?</div></td>"
end end

@ -7,7 +7,8 @@ module Docs
code: 'https://github.com/mdn/content' 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 <script type="application/json" id="hydration">
html_filters.push 'mdn/clean_html'
options[:container] = '#content > .main-page-content' options[:container] = '#content > .main-page-content'
options[:trailing_slash] = false options[:trailing_slash] = false

Loading…
Cancel
Save