-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathgetTitle.js
More file actions
20 lines (18 loc) · 680 Bytes
/
Copy pathgetTitle.js
File metadata and controls
20 lines (18 loc) · 680 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict'
const getTitle = (article, articleType) => {
try {
switch(articleType) {
case "regular":
return (article.find('h4').text() || article.find('div > div + div > div a').text() || "").trim() || ""
case "topicFeatured":
return (article.find('a[target=_blank]').text() || (article.find('button').attr('aria-label')?.replace('More - ', '')) || "").trim() || ""
case "topicSmall":
return (article.find('a[target=_blank]').text() || (article.find('button').attr('aria-label')?.replace('More - ', '')) || "").trim() || ""
default:
return "";
}
} catch (err) {
return "";
}
}
module.exports = getTitle