[devdocsgjs/main: 1679/1867] Use MDN scraper for web extensions
- From: Andy Holmes <andyholmes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devdocsgjs/main: 1679/1867] Use MDN scraper for web extensions
- Date: Fri, 19 Nov 2021 23:48:14 +0000 (UTC)
commit 6abc208535b8c2ddeef833c0199ba59642d30ed8
Author: Cimbali <me cimba li>
Date: Wed May 26 22:27:26 2021 +0200
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(-)
---
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
- <a href="#{filter.current_url}">#{filter.result()[:entries][0].name}</a> © 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]