Skip to content

Commit 47ec0e5

Browse files
committed
Simplify publisher rules
1 parent a36e240 commit 47ec0e5

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

packages/metascraper-publisher/index.js

+7-19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const wrap = rule => ({ htmlDom }) => {
1818
return isString(value) && condenseWhitespace(value)
1919
}
2020

21+
const getFromTitle = (text, regex) => {
22+
const matches = regex.exec(text)
23+
return matches ? matches[1] : false
24+
}
25+
2126
/**
2227
* Rules.
2328
*/
@@ -39,24 +44,7 @@ module.exports = () => ({
3944
wrap($ => $('[class*="brand"]').text()),
4045
wrap($ => $('[class*="logo"] a img[alt]').attr('alt')),
4146
wrap($ => $('[class*="logo"] img[alt]').attr('alt')),
42-
wrap($ => {
43-
const title = $('title')
44-
.text()
45-
.trim()
46-
const matches = REGEX_TITLE.exec(title)
47-
if (!matches) return
48-
return matches[1]
49-
}),
50-
wrap($ =>
51-
$('[itemtype="http://schema.org/Blog"] [itemprop="name"]').attr('content')
52-
),
53-
wrap($ => {
54-
const desc = $('link[rel="alternate"][type="application/atom+xml"]').attr(
55-
'title'
56-
)
57-
const matches = REGEX_RSS.exec(desc)
58-
if (!matches) return
59-
return matches[1]
60-
})
47+
wrap($ => getFromTitle($('title').text(), REGEX_TITLE)),
48+
wrap($ => getFromTitle($('link[type*="xml"]').attr('title'), REGEX_RSS))
6149
]
6250
})

0 commit comments

Comments
 (0)