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/hackernews.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/hackernews.js (limited to 'examples/hackernews.js') diff --git a/examples/hackernews.js b/examples/hackernews.js new file mode 100644 index 0000000..71dc52f --- /dev/null +++ b/examples/hackernews.js @@ -0,0 +1,25 @@ +export const config = { + url: "https://news.ycombinator.com/", + depth: 9, + cache: "file", + follow: ["a.morelink[href]"], +}; + +export default function({ doc, absoluteURL }) { + const posts = doc.find(".athing"); + + return { + posts: posts.map((post) => { + const link = post.find(".titleline > a"); + const meta = post.next(); + + return { + url: absoluteURL(link.attr("href")), + user: meta.find(".hnuser").text(), + title: link.text(), + points: meta.find(".score").text().replace(" points", ""), + created: meta.find(".age").attr("title"), + }; + }), + }; +} -- cgit v1.2.3