Use MDN scraper for web extensions

This commit is contained in:
Cimbali 2021-05-26 22:27:26 +02:00
parent 21443dc914
commit 6abc208535
3 changed files with 11 additions and 28 deletions

View file

@ -2,12 +2,7 @@ module Docs
class WebExtensions
class CleanHtmlFilter < Filter
def call
# Remove all the cruft.
content = at_css('main#content')
content.at_css('aside.metadata').remove
content
doc
end
end
end

View file

@ -1,26 +1,22 @@
module Docs
class WebExtensions
class EntriesFilter < Docs::EntriesFilter
TYPE_BY_PATH = {
'manifest.json' => 'manifest.json',
'user_interface' => 'User Interface',
'WebRequest' => 'webRequest',
}
def get_name
at_css('main#content h1').text
at_css('h1').text
end
def get_type
slug_parts = slug.split('/')
if slug_parts[0] == 'API' and slug_parts.length() > 1
if slug_parts[1] == 'WebRequest'
return 'webRequest'
else
return slug_parts[1]
end
elsif slug_parts[0] == 'manifest.json'
return slug_parts[0]
elsif slug_parts[0] == 'user_interface'
return 'User Interface'
elsif slug_parts.length() > 1
return slug_parts[0]
return TYPE_BY_PATH.fetch(slug_parts[1], slug_parts[1])
else
return 'Miscellaneous'
return TYPE_BY_PATH.fetch(slug_parts[0], slug_parts.length() > 1 ? slug_parts[0] : 'Miscellaneous')
end
end
end

View file

@ -1,8 +1,7 @@
module Docs
class WebExtensions < UrlScraper
class WebExtensions < Mdn
self.name = 'Web Extensions'
self.slug = 'web_extensions'
self.type = 'simple'
self.links = {
home: 'https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions'
}
@ -15,12 +14,5 @@ module Docs
/\/contributors\.txt$/
]
options[:attribution] = -> (filter) {
<<-HTML
<a href="#{filter.current_url}">#{filter.result()[:entries][0].name}</a> &copy; 2005-2021 Mozilla and individual contributors.<br>
Licensed under the <a href="https://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-ShareAlike license</a>
HTML
}
end
end