diff --git a/lib/docs/filters/web_extensions/clean_html.rb b/lib/docs/filters/web_extensions/clean_html.rb new file mode 100644 index 00000000..c5737371 --- /dev/null +++ b/lib/docs/filters/web_extensions/clean_html.rb @@ -0,0 +1,14 @@ +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 + end + end + end +end diff --git a/lib/docs/filters/web_extensions/entries.rb b/lib/docs/filters/web_extensions/entries.rb new file mode 100644 index 00000000..84c095e7 --- /dev/null +++ b/lib/docs/filters/web_extensions/entries.rb @@ -0,0 +1,28 @@ +module Docs + class WebExtensions + class EntriesFilter < Docs::EntriesFilter + def get_name + at_css('main#content 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] + else + return 'Miscellaneous' + end + end + end + end +end diff --git a/lib/docs/scrapers/web_extensions.rb b/lib/docs/scrapers/web_extensions.rb new file mode 100644 index 00000000..15d2c30a --- /dev/null +++ b/lib/docs/scrapers/web_extensions.rb @@ -0,0 +1,26 @@ +module Docs + class WebExtensions < UrlScraper + 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' + } + + self.base_url = 'https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions' + + html_filters.push 'web_extensions/entries', 'web_extensions/clean_html' + + options[:skip_patterns] = [ + /\/contributors\.txt$/ + ] + + options[:attribution] = -> (filter) { + <<-HTML + #{filter.result()[:entries][0].name} © 2005-2021 Mozilla and individual contributors.
+ Licensed under the Creative Commons Attribution-ShareAlike license + HTML + } + + end +end