summaryrefslogtreecommitdiff
path: root/examples/custom_headers.js
blob: 6435a391be44d72c9763657788ffde6bf8e1ea46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
export const config = {
  url: "https://news.ycombinator.com/",
  headers: {
    "Authorization": "Basic ZGVtbzpwQDU1dzByZA==",
    "User-Agent":    "Gecko/1.0",
  }
};

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"),
      };
    }),
  };
}