Merge pull request #1638 from freeCodeCamp/mdn

Update MDN documentation
pull/1642/head
Simon Legner 3 years ago committed by GitHub
commit 10448a0a0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2222,7 +2222,7 @@ function urlencode(o) {
return pairs.join('&'); return pairs.join('&');
} }
// borrowed from https://tools.ietf.org/html/rfc3986#appendix-B // borrowed from https://datatracker.ietf.org/doc/html/rfc3986#appendix-B
// intentionally using regex and not <a/> href parsing trick because React Native and other // intentionally using regex and not <a/> href parsing trick because React Native and other
// environments where DOM might not be available // environments where DOM might not be available
function parseUrl(url) { function parseUrl(url) {

@ -107,7 +107,7 @@
code > strong { font-weight: normal; } code > strong { font-weight: normal; }
// Compatibility tablees // Compatibility tables
.bc-github-link { .bc-github-link {
float: right; float: right;
@ -115,6 +115,7 @@
} }
.bc-supports-yes, .bc-supports-yes + dd, .bc-supports-yes + dd + dd { background: var(--noteGreenBackground); } .bc-supports-yes, .bc-supports-yes + dd, .bc-supports-yes + dd + dd { background: var(--noteGreenBackground); }
.bc-supports-unknown, .bc-supports-unknown + dd, .bc-supports-unknown + dd + dd { background: var(--noteBackground); }
.bc-supports-partial, .bc-supports-partial + dd, .bc-supports-partial + dd + dd { background: var(--noteOrangeBackground); } .bc-supports-partial, .bc-supports-partial + dd, .bc-supports-partial + dd + dd { background: var(--noteOrangeBackground); }
.bc-supports-no, .bc-supports-no + dd, .bc-supports-no + dd + dd { background: var(--noteRedBackground); } .bc-supports-no, .bc-supports-no + dd, .bc-supports-no + dd + dd { background: var(--noteRedBackground); }
@ -130,4 +131,8 @@
dd { margin: 0; } dd { margin: 0; }
} }
iframe.interactive {
width: 100%;
}
} }

@ -2,7 +2,7 @@ module Docs
class Http class Http
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
current_url.host == 'tools.ietf.org' ? ietf : mdn current_url.host == 'datatracker.ietf.org' ? ietf : mdn
doc doc
end end
@ -43,7 +43,7 @@ module Docs
end end
css('.selflink').each do |node| css('.selflink').each do |node|
node.parent['id'] = node['name'] node.parent['id'] = node['id']
node.before(node.children).remove node.before(node.children).remove
end end

@ -2,7 +2,7 @@ module Docs
class Http class Http
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
if current_url.host == 'tools.ietf.org' if current_url.host == 'datatracker.ietf.org'
name = at_css('h1').content name = at_css('h1').content
name.remove! %r{\A.+\:} name.remove! %r{\A.+\:}
name.remove! %r{\A.+\-\-} name.remove! %r{\A.+\-\-}
@ -22,7 +22,7 @@ module Docs
end end
def get_type def get_type
return name if current_url.host == 'tools.ietf.org' return name if current_url.host == 'datatracker.ietf.org'
if slug.start_with?('Headers/Content-Security-Policy') if slug.start_with?('Headers/Content-Security-Policy')
'CSP' 'CSP'
@ -101,7 +101,7 @@ module Docs
LEVEL_3 = /\A(\d+)\.\d+\.\d+\z/ LEVEL_3 = /\A(\d+)\.\d+\.\d+\z/
def additional_entries def additional_entries
return [] unless current_url.host == 'tools.ietf.org' return [] unless current_url.host == 'datatracker.ietf.org'
type = nil type = nil
css('a[href^="#section-"]').each_with_object([]) do |node, entries| css('a[href^="#section-"]').each_with_object([]) do |node, entries|

@ -46,7 +46,9 @@ module Docs
end end
def request_bcd_uris def request_bcd_uris
index_json = JSON.load(Net::HTTP.get(URI(current_url.to_s + '/index.json'))) url = current_url.to_s + '/index.json'
response = Request.run url
index_json = JSON.load response.body
uris = [] uris = []
@ -63,9 +65,9 @@ module Docs
return uris return uris
end end
def generate_compatibility_table_wrapper(uri) def generate_compatibility_table_wrapper(url)
response = Request.run url
@json_data = JSON.load(Net::HTTP.get(URI(uri)))['data'] @json_data = JSON.load(response.body)['data']
html_table = generate_basic_html_table() html_table = generate_basic_html_table()
@ -163,15 +165,14 @@ module Docs
version_added.map! do |version| version_added.map! do |version|
if version == true if version == true
version = 'Yes' 'Yes'
elsif version == false elsif version == false
version = 'No' 'No'
elsif version.is_a?(String) elsif version.is_a?(String)
version
else else
version = '?' '?'
end end
version
end end
if version_removed[0] if version_removed[0]
@ -179,6 +180,8 @@ module Docs
else else
if 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] == '?'
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
@ -201,7 +204,7 @@ module Docs
end end
else else
format_string = "<td class=bc-supports-no><div>?</div></td>" format_string = "<td class=bc-supports-unknown><div>?</div></td>"
end end
entry.add_child(format_string) entry.add_child(format_string)

@ -2,15 +2,25 @@ module Docs
class Http < Mdn class Http < Mdn
include MultipleBaseUrls include MultipleBaseUrls
# release = '2021-10-22'
self.name = 'HTTP' self.name = 'HTTP'
self.base_urls = ['https://developer.mozilla.org/en-US/docs/Web/HTTP', 'https://tools.ietf.org/html/'] self.base_urls = [
'https://developer.mozilla.org/en-US/docs/Web/HTTP',
'https://datatracker.ietf.org/doc/html/',
]
html_filters.push 'http/clean_html', 'http/entries', 'title' html_filters.push 'http/clean_html', 'http/entries', 'title'
options[:root_title] = 'HTTP' options[:root_title] = 'HTTP'
options[:title] = ->(filter) { filter.current_url.host == 'tools.ietf.org' ? false : filter.default_title } options[:title] = ->(filter) do
options[:container] = ->(filter) { filter.current_url.host == 'tools.ietf.org' ? '.content' : nil } filter.current_url.host == 'datatracker.ietf.org' ? false : filter.default_title
options[:skip_links] = ->(filter) { filter.current_url.host == 'tools.ietf.org' ? true : false } end
options[:container] = ->(filter) do
filter.current_url.host == 'datatracker.ietf.org' ? '.content .draftcontent' : Docs::Mdn.options[:container]
end
options[:skip_links] = ->(filter) do
filter.current_url.host == 'datatracker.ietf.org' ? true : false
end
options[:replace_paths] = { '/Access_control_CORS' => '/CORS' } options[:replace_paths] = { '/Access_control_CORS' => '/CORS' }
options[:fix_urls] = ->(url) do options[:fix_urls] = ->(url) do
url.sub! %r{(Status/\d\d\d)_[A-Z].+}, '\1' url.sub! %r{(Status/\d\d\d)_[A-Z].+}, '\1'
@ -18,7 +28,7 @@ module Docs
end end
options[:attribution] = ->(filter) do options[:attribution] = ->(filter) do
if filter.current_url.host == 'tools.ietf.org' if filter.current_url.host == 'datatracker.ietf.org'
"&copy; document authors. All rights reserved." "&copy; document authors. All rights reserved."
else else
Docs::Mdn.options[:attribution] Docs::Mdn.options[:attribution]
@ -27,16 +37,16 @@ module Docs
def initial_urls def initial_urls
%w(https://developer.mozilla.org/en-US/docs/Web/HTTP %w(https://developer.mozilla.org/en-US/docs/Web/HTTP
https://tools.ietf.org/html/rfc2616 https://datatracker.ietf.org/doc/html/rfc2616
https://tools.ietf.org/html/rfc4918 https://datatracker.ietf.org/doc/html/rfc4918
https://tools.ietf.org/html/rfc7230 https://datatracker.ietf.org/doc/html/rfc7230
https://tools.ietf.org/html/rfc7231 https://datatracker.ietf.org/doc/html/rfc7231
https://tools.ietf.org/html/rfc7232 https://datatracker.ietf.org/doc/html/rfc7232
https://tools.ietf.org/html/rfc7233 https://datatracker.ietf.org/doc/html/rfc7233
https://tools.ietf.org/html/rfc7234 https://datatracker.ietf.org/doc/html/rfc7234
https://tools.ietf.org/html/rfc7235 https://datatracker.ietf.org/doc/html/rfc7235
https://tools.ietf.org/html/rfc7540 https://datatracker.ietf.org/doc/html/rfc7540
https://tools.ietf.org/html/rfc5023) https://datatracker.ietf.org/doc/html/rfc5023)
end end
end end
end end

@ -1,5 +1,6 @@
module Docs module Docs
class Css < Mdn class Css < Mdn
# release = '2021-10-22'
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,6 +1,7 @@
module Docs module Docs
class Dom < Mdn class Dom < Mdn
# release = '2021-10-22'
self.name = 'DOM' self.name = '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,6 +2,7 @@ module Docs
class Html < Mdn class Html < Mdn
prepend FixInternalUrlsBehavior prepend FixInternalUrlsBehavior
# release = '2021-10-22'
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'

@ -3,6 +3,7 @@ module Docs
prepend FixInternalUrlsBehavior prepend FixInternalUrlsBehavior
prepend FixRedirectionsBehavior prepend FixRedirectionsBehavior
# release = '2021-10-22'
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'

@ -3,6 +3,7 @@ module Docs
prepend FixInternalUrlsBehavior prepend FixInternalUrlsBehavior
prepend FixRedirectionsBehavior prepend FixRedirectionsBehavior
# release = '2021-10-22'
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'

@ -1,5 +1,6 @@
module Docs module Docs
class WebExtensions < Mdn class WebExtensions < Mdn
# release = '2021-10-22'
self.name = 'Web Extensions' self.name = 'Web Extensions'
self.slug = 'web_extensions' self.slug = 'web_extensions'
self.links = { self.links = {

@ -1,5 +1,6 @@
module Docs module Docs
class XsltXpath < Mdn class XsltXpath < Mdn
# release = '2021-10-22'
self.name = 'XSLT & XPath' self.name = 'XSLT & XPath'
self.slug = 'xslt_xpath' self.slug = 'xslt_xpath'
self.base_url = 'https://developer.mozilla.org/en-US/docs/Web' self.base_url = 'https://developer.mozilla.org/en-US/docs/Web'

Loading…
Cancel
Save