Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/(marketing)/trending/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Link from "next/link";
import { serviceClient } from "@/lib/supabase/service";
import { currentTrends } from "@/lib/ads/trends";
import { pitSearchUrl } from "@/lib/ads/trendList";
import { TREND_WINDOW_DAYS, trendsAreStale } from "@/lib/ads/trending";

export const metadata = {
Expand Down Expand Up @@ -80,7 +81,11 @@ export default async function TrendingPage() {
{topics.map((topic, index) => (
<tr key={topic.topic} className="border-b border-[var(--color-border)]">
<td className="py-2 pr-3 text-[var(--color-muted)]">{index + 1}</td>
<td className="py-2 pr-3 font-medium">{topic.label ?? topic.topic}</td>
<td className="py-2 pr-3 font-medium">
<a href={pitSearchUrl(topic.label ?? topic.topic)} className="underline-offset-2 hover:underline">
{topic.label ?? topic.topic}
</a>
</td>
<td className="py-2 pr-3 text-right tabular-nums">{topic.mentions}</td>
<td className="py-2 pr-3 text-right tabular-nums">{topic.priorMentions}</td>
<td className="py-2 text-right tabular-nums">{change(topic.mentions, topic.priorMentions)}</td>
Expand Down
6 changes: 6 additions & 0 deletions lib/ads/trendList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import type { SupabaseClient } from "@supabase/supabase-js";
import { currentTrends } from "./trends";
import { TREND_MAX_AGE_HOURS, TREND_SOURCE, TREND_WINDOW_DAYS, trendsAreStale } from "./trending";

/** Where a subject can be searched. */
export function pitSearchUrl(subject: string): string {
return `https://pit.world/search?q=${encodeURIComponent(subject)}`;
}

export async function publicTrendList(sb: SupabaseClient, options: { limit?: number; now?: number } = {}) {
const now = options.now ?? Date.now();
const limit = Math.min(200, Math.max(1, Math.round(Number(options.limit)) || 50));
Expand All @@ -26,6 +31,7 @@ export async function publicTrendList(sb: SupabaseClient, options: { limit?: num
score: signal.score,
feeds: signal.mentions,
prior_feeds: signal.priorMentions,
search_url: pitSearchUrl(signal.label ?? signal.topic),
})),
};
}
9 changes: 8 additions & 1 deletion tests/ads-trend-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ describe("publicTrendList", () => {
const list = await publicTrendList(client([row("midterm result", "midterm results", "2026-11-07T11:00:00Z")]), { now: NOW });
expect(list.stale).toBe(false);
expect(list.topics).toEqual([
{ topic: "midterm results", match_key: "midterm result", score: 40, feeds: 60, prior_feeds: 2 },
{
topic: "midterm results",
match_key: "midterm result",
score: 40,
feeds: 60,
prior_feeds: 2,
search_url: "https://pit.world/search?q=midterm%20results",
},
]);
});

Expand Down