summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/node_modules/metascraper-description/index.js
blob: 16ad9caa725217d1e08b49084daa1fd778733c65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict'

const { $jsonld, description } = require('@metascraper/helpers')

/**
 * Wrap a rule with validation and formatting logic.
 *
 * @param {Function} rule
 * @return {Function} wrapped
 */

const createWrap = opts => rule => ({ htmlDom, url }) => {
  const value = rule(htmlDom, url)
  return description(value, opts)
}

/**
 * Rules.
 */

module.exports = opts => {
  const wrap = createWrap(opts)
  return {
    description: [
      wrap($jsonld('description')),
      wrap($ => $('meta[property="og:description"]').attr('content')),
      wrap($ => $('meta[name="twitter:description"]').attr('content')),
      wrap($ => $('meta[name="description"]').attr('content')),
      wrap($ => $('meta[itemprop="description"]').attr('content')),
      wrap($jsonld('articleBody'))
    ]
  }
}