Merge pull request #1972 from freeCodeCamp/mdn-fix-bcd

MDN scrapers: fix browser compatibility table
pull/1968/head
Simon Legner 2 years ago committed by GitHub
commit 214da8c130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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>"
else elsif version_added[0] == 'No'
if version_added[0] == 'No'
format_string = "<td class=bc-supports-no>" format_string = "<td class=bc-supports-no>"
elsif version_added[0] == '?' elsif version_added[0] == '?'
format_string = "<td class=bc-supports-unknown>" format_string = "<td class=bc-supports-unknown>"
else else
format_string = "<td class=bc-supports-yes>" 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
if version_added[value] == 'No'
format_string += "<div>#{version_added[value]}</div>"
else else
format_string += "<div>#{version_added[value]}</div>" version_string = version_added[value]
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

@ -1,6 +1,6 @@
module Docs module Docs
class Css < Mdn class Css < Mdn
# release = '2023-01-06' # release = '2023-04-24'
self.name = 'CSS' self.name = 'CSS'
self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/CSS' self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/CSS'
self.root_path = '/Reference' self.root_path = '/Reference'

@ -1,7 +1,7 @@
module Docs module Docs
class Dom < Mdn class Dom < Mdn
# release = '2023-01-06' # release = '2023-04-24'
self.name = 'Web APIs' self.name = 'Web APIs'
self.slug = 'dom' self.slug = 'dom'
self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/API' self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/API'

@ -2,7 +2,7 @@ module Docs
class Html < Mdn class Html < Mdn
prepend FixInternalUrlsBehavior prepend FixInternalUrlsBehavior
# release = '2023-01-06' # release = '2023-04-24'
self.name = 'HTML' self.name = 'HTML'
self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/HTML' self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/HTML'
self.links = { self.links = {

@ -3,7 +3,7 @@ module Docs
prepend FixInternalUrlsBehavior prepend FixInternalUrlsBehavior
prepend FixRedirectionsBehavior prepend FixRedirectionsBehavior
# release = '2023-01-06' # release = '2023-04-24'
self.name = 'JavaScript' self.name = 'JavaScript'
self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference' self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference'
self.links = { self.links = {

@ -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

@ -3,7 +3,7 @@ module Docs
prepend FixInternalUrlsBehavior prepend FixInternalUrlsBehavior
prepend FixRedirectionsBehavior prepend FixRedirectionsBehavior
# release = '2022-09-06' # release = '2023-04-24'
self.name = 'SVG' self.name = 'SVG'
self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/SVG' self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/SVG'
self.links = { self.links = {

@ -1,6 +1,6 @@
module Docs module Docs
class WebExtensions < Mdn class WebExtensions < Mdn
# release = '2022-09-06' # release = '2023-04-24'
self.name = 'Web Extensions' self.name = 'Web Extensions'
self.slug = 'web_extensions' self.slug = 'web_extensions'
self.links = { self.links = {

Loading…
Cancel
Save