summaryrefslogtreecommitdiff
path: root/examples/hackernews.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/hackernews.js
parent135eff4287c06aff9604a4d0b9ddea1740f6c836 (diff)
Add examples
Diffstat (limited to 'examples/hackernews.js')
-rw-r--r--examples/hackernews.js25
1 files changed, 25 insertions, 0 deletions
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"),
+ };
+ }),
+ };
+}