From 6abc208535b8c2ddeef833c0199ba59642d30ed8 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Wed, 26 May 2021 22:27:26 +0200 Subject: [PATCH] Use MDN scraper for web extensions --- lib/docs/filters/web_extensions/clean_html.rb | 7 +----- lib/docs/filters/web_extensions/entries.rb | 22 ++++++++----------- lib/docs/scrapers/{ => mdn}/web_extensions.rb | 10 +-------- 3 files changed, 11 insertions(+), 28 deletions(-) rename lib/docs/scrapers/{ => mdn}/web_extensions.rb (52%) diff --git a/lib/docs/filters/web_extensions/clean_html.rb b/lib/docs/filters/web_extensions/clean_html.rb index c5737371..88ec0373 100644 --- a/lib/docs/filters/web_extensions/clean_html.rb +++ b/lib/docs/filters/web_extensions/clean_html.rb @@ -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 diff --git a/lib/docs/filters/web_extensions/entries.rb b/lib/docs/filters/web_extensions/entries.rb index 84c095e7..f04efb37 100644 --- a/lib/docs/filters/web_extensions/entries.rb +++ b/lib/docs/filters/web_extensions/entries.rb @@ -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 diff --git a/lib/docs/scrapers/web_extensions.rb b/lib/docs/scrapers/mdn/web_extensions.rb similarity index 52% rename from lib/docs/scrapers/web_extensions.rb rename to lib/docs/scrapers/mdn/web_extensions.rb index 15d2c30a..1a5f528a 100644 --- a/lib/docs/scrapers/web_extensions.rb +++ b/lib/docs/scrapers/mdn/web_extensions.rb @@ -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 - #{filter.result()[:entries][0].name} © 2005-2021 Mozilla and individual contributors.
- Licensed under the Creative Commons Attribution-ShareAlike license - HTML - } - end end