/ clis / producthunt / today.js
today.js
 1  /**
 2   * Product Hunt today's top launches — filtered from public Atom feed.
 3   *
 4   * Shows the most recently published day's products (Product Hunt runs on
 5   * Pacific Time; the feed date may differ from UTC local date by up to 1 day).
 6   */
 7  import { cli, Strategy } from '@jackwener/opencli/registry';
 8  import { fetchFeed } from './utils.js';
 9  cli({
10      site: 'producthunt',
11      name: 'today',
12      description: "Today's Product Hunt launches (most recent day in feed)",
13      domain: 'www.producthunt.com',
14      strategy: Strategy.PUBLIC,
15      args: [
16          { name: 'limit', type: 'int', default: 20, help: 'Max results' },
17      ],
18      columns: ['rank', 'name', 'tagline', 'author', 'url'],
19      func: async (_page, args) => {
20          const count = Math.min(Number(args.limit) || 20, 50);
21          const posts = await fetchFeed();
22          if (posts.length === 0)
23              return [];
24          // Use the latest date in the feed (Product Hunt is PST-based)
25          const latestDate = posts.map(p => p.date).sort().reverse()[0];
26          const todayPosts = posts.filter(p => p.date === latestDate);
27          return todayPosts.slice(0, count).map((p, i) => ({
28              rank: i + 1,
29              name: p.name,
30              tagline: p.tagline,
31              author: p.author,
32              url: p.url,
33          }));
34      },
35  });