Files
dark-lord/lib/forumSort.ts
drjones 78a071ba02 Harden onion boot flow and deepen site surfaces
Add persistent onion key backup and restore, improve startup resilience, and flesh out the major site verticals with richer navigation, search coverage, and operator documentation.

Made-with: Cursor
2026-04-07 21:35:52 -07:00

23 lines
747 B
TypeScript

import { displayScore, type ForumThread } from "@/lib/forumState";
export type ForumSortMode = "hot" | "new" | "top";
function hoursSince(ts: number): number {
return (Date.now() - ts) / 3600000;
}
export function hotRank(t: ForumThread): number {
const s = displayScore(t);
const engagement = t.replies.length * 4;
const freshness = Math.max(0, 72 - hoursSince(t.ts)) * 2;
return s + engagement + freshness;
}
export function sortThreads(list: ForumThread[], mode: ForumSortMode): ForumThread[] {
const copy = [...list];
if (mode === "new") copy.sort((a, b) => b.ts - a.ts);
else if (mode === "top") copy.sort((a, b) => displayScore(b) - displayScore(a));
else copy.sort((a, b) => hotRank(b) - hotRank(a));
return copy;
}