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
This commit is contained in:
22
lib/forumSort.ts
Normal file
22
lib/forumSort.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user