Skip to content
Closed
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
35 changes: 35 additions & 0 deletions app/(marketing)/trending/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,25 @@ function updated(iso: string): string {
return new Date(iso).toLocaleDateString("en-US", { month: "short", day: "numeric", timeZone: "UTC" });
}

type VotedSearch = { phrase: string; votes: number };

// Searches people voted on at pit.world. An extra, so any failure just hides it.
async function votedSearches(): Promise<VotedSearch[]> {
try {
const res = await fetch("https://pit.world/api/voted-searches?limit=20", {
next: { revalidate: 3600 },
signal: AbortSignal.timeout(5_000),
});
if (!res.ok) return [];
const body = (await res.json()) as { topics?: VotedSearch[] };
return Array.isArray(body.topics) ? body.topics : [];
} catch {
return [];
}
}

export default async function TrendingPage() {
const voted = await votedSearches();
const topics = await currentTrends(serviceClient(), { limit: LIMIT, includeStale: true });
const newest = topics.reduce<string | null>(
(latest, topic) => (!latest || (topic.ingestedAt ?? "") > latest ? (topic.ingestedAt ?? latest) : latest),
Expand Down Expand Up @@ -94,6 +112,23 @@ export default async function TrendingPage() {
</div>
)}

{voted.length > 0 && (
<section className="mt-10">
<h2 className="font-semibold">Most voted searches on pit.world</h2>
<p className="mt-1 text-sm text-[var(--color-muted)]">
Searches people cared enough about to vote on their results, this week.
</p>
<ul className="mt-3 space-y-1 text-sm">
{voted.map((search) => (
<li key={search.phrase} className="flex justify-between border-b border-[var(--color-border)] py-1">
<span>{search.phrase}</span>
<span className="tabular-nums text-[var(--color-muted)]">{search.votes}</span>
</li>
))}
</ul>
</section>
)}

<div className="card mt-10 p-5">
<h2 className="font-semibold">Run ads where these subjects are read</h2>
<p className="mt-1 text-sm text-[var(--color-muted)]">
Expand Down