From 2bfae5b426bf4a0b99d3979ed12d63cb50c39b17 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Thu, 19 Oct 2023 20:43:04 +0200 Subject: Add examples --- examples/reddit.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/reddit.js (limited to 'examples/reddit.js') 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")), + }; + }), + }; +} -- cgit v1.2.3