summaryrefslogtreecommitdiff
path: root/examples/reddit.js
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2023-10-19 20:43:04 +0200
committerPhilipp Tanlak <philipp.tanlak@gmail.com>2023-10-19 20:43:04 +0200
commit2bfae5b426bf4a0b99d3979ed12d63cb50c39b17 (patch)
treed1a3c622e9b13e66e16b3e7b96068c67933ad950 /examples/reddit.js
parent135eff4287c06aff9604a4d0b9ddea1740f6c836 (diff)
Add examples
Diffstat (limited to 'examples/reddit.js')
-rw-r--r--examples/reddit.js33
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")),
+ };
+ }),
+ };
+}