diff options
Diffstat (limited to 'examples/reddit.js')
| -rw-r--r-- | examples/reddit.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/reddit.js b/examples/reddit.js new file mode 100644 index 0000000..bd4e9c3 --- /dev/null +++ b/examples/reddit.js @@ -0,0 +1,33 @@ +export const config = { + url: "https://old.reddit.com/", +}; + +export default function({ doc, absoluteURL }) { + const posts = doc.find("#siteTable .thing:not(.promoted)"); + + return { + posts: posts.map((post) => { + const rank = post.find(".rank"); + const user = post.find(".author"); + const created = post.find("time"); + const title = post.find("a.title"); + const comments = post.find(".comments"); + const subreddit = post.find(".subreddit"); + const upvotes = post.find(".score.unvoted"); + const thumbnail = post.find("a.thumbnail img"); + + return { + rank: rank.text(), + user: user.text(), + created: created.attr("datetime"), + title: title.text(), + link: absoluteURL(title.attr("href")), + comments: comments.text().replace(" comments", ""), + comments_link: comments.attr("href"), + subreddit: subreddit.text(), + upvotes: upvotes.text(), + thumbnail: absoluteURL(thumbnail.attr("src")), + }; + }), + }; +} |