-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetLatestArticles.js
41 lines (37 loc) · 1.02 KB
/
getLatestArticles.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
const Xray = require("x-ray")
const URL = require("url").URL
const X = Xray({
filters: {
trim: value => value.trim(),
parseName: value => value.split("・")[0]
}
})
module.exports = async tag => {
const articles = await X(
`https://dev.to/t/${tag}/latest`,
"#substories .single-article",
[
{
title: ".index-article-link .content h3 | trim",
link: ".index-article-link@href",
tags: [".tags .tag"],
author: {
name: "h4 a | parseName",
link: ".small-pic-link-wrapper@href"
}
}
]
).then(articles => articles.filter(article => article.title))
// get twitter handle
for (article of articles) {
const socialLinks = await X(article.author.link, [
".profile-details .social a@href"
])
const twitter = socialLinks.find(url => url.includes("twitter.com/"))
if (twitter) {
const twitterURL = new URL(twitter)
article.author.twitterHandle = `@${twitterURL.pathname.substring(1)}`
}
}
return articles
}