-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathindex.js
49 lines (43 loc) · 1.83 KB
/
index.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict'
const { $filter, $jsonld, publisher, toRule } = require('@metascraper/helpers')
const REGEX_TITLE = /^.*?[-|]\s+(.*)$/
const toPublisher = toRule(publisher)
const getFromTitle = (text, regex = REGEX_TITLE) => {
const matches = regex.exec(text)
if (!matches) return false
let result = matches[1]
while (regex.test(result)) result = regex.exec(result)[1]
return result
}
module.exports = () => ({
publisher: [
toPublisher($jsonld('publisher.name')),
toPublisher($ => $('meta[property="og:site_name"]').attr('content')),
toPublisher($ => $('meta[name*="application-name" i]').attr('content')),
toPublisher($ => $('meta[name*="app-title" i]').attr('content')),
toPublisher($ => $('meta[property*="app_name" i]').attr('content')),
toPublisher($ => $('meta[name="publisher" i]').attr('content')),
toPublisher($ => $('meta[name="twitter:app:name:iphone"]').attr('content')),
toPublisher($ =>
$('meta[property="twitter:app:name:iphone"]').attr('content')
),
toPublisher($ => $('meta[name="twitter:app:name:ipad"]').attr('content')),
toPublisher($ =>
$('meta[property="twitter:app:name:ipad"]').attr('content')
),
toPublisher($ =>
$('meta[name="twitter:app:name:googleplay"]').attr('content')
),
toPublisher($ =>
$('meta[property="twitter:app:name:googleplay"]').attr('content')
),
toPublisher($ => $filter($, $('#logo'))),
toPublisher($ => $filter($, $('.logo'))),
toPublisher($ => $filter($, $('a[class*="brand" i]'))),
toPublisher($ => $filter($, $('[class*="brand" i]'))),
toPublisher($ => $('[class*="logo" i] a img[alt]').attr('alt')),
toPublisher($ => $('[class*="logo" i] img[alt]').attr('alt')),
toPublisher($ => $filter($, $('title'), el => getFromTitle($filter.fn(el))))
]
})
module.exports.getFromTitle = getFromTitle