summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/node_modules/metascraper-author/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/metascraper-author/index.js')
-rw-r--r--bin/wiki/ImportarDesdeURL/node_modules/metascraper-author/index.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/metascraper-author/index.js b/bin/wiki/ImportarDesdeURL/node_modules/metascraper-author/index.js
new file mode 100644
index 00000000..53d6bd1b
--- /dev/null
+++ b/bin/wiki/ImportarDesdeURL/node_modules/metascraper-author/index.js
@@ -0,0 +1,51 @@
+'use strict'
+
+const { $jsonld, $filter, author } = require('@metascraper/helpers')
+
+const REGEX_STRICT = /^\S+\s+\S+/
+
+/**
+ * Wrap a rule with validation and formatting logic.
+ *
+ * @param {Function} rule
+ * @return {Function} wrapped
+ */
+
+const wrap = rule => ({ htmlDom, url }) => {
+ const value = rule(htmlDom, url)
+ return author(value)
+}
+
+/**
+ * Enforce stricter matching for a `rule`.
+ *
+ * @param {Function} rule
+ * @return {Function} stricter
+ */
+
+const strict = rule => $ => {
+ const value = rule($)
+ return REGEX_STRICT.test(value) && value
+}
+
+/**
+ * Rules.
+ */
+
+module.exports = () => ({
+ author: [
+ wrap($jsonld('author.name')),
+ wrap($ => $('meta[name="author"]').attr('content')),
+ wrap($ => $('meta[property="author"]').attr('content')),
+ wrap($ => $('meta[property="article:author"]').attr('content')),
+ wrap($ => $filter($, $('[itemprop*="author" i] [itemprop="name"]'))),
+ wrap($ => $filter($, $('[itemprop*="author" i]'))),
+ wrap($ => $filter($, $('[rel="author"]'))),
+ strict(wrap($ => $filter($, $('a[class*="author" i]')))),
+ strict(wrap($ => $filter($, $('[class*="author" i] a')))),
+ strict(wrap($ => $filter($, $('a[href*="/author/" i]')))),
+ wrap($ => $filter($, $('a[class*="screenname" i]'))),
+ strict(wrap($ => $filter($, $('[class*="author" i]')))),
+ strict(wrap($ => $filter($, $('[class*="byline" i]'))))
+ ]
+})