mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-06-05 19:15:30 -04:00
5fc9efb181
- Introduced a new PostStats component to handle view and comment counts, replacing the previous async implementation with a client-side approach. - Updated CommentCount component to use client-side state management for fetching comment counts. - Removed unnecessary caching logic from view and comment fetching functions. - Simplified date formatting by moving it inline, enhancing performance and readability.
30 lines
718 B
TypeScript
30 lines
718 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getAllViewCounts } from "@/lib/server/views";
|
|
|
|
export const GET = async (): Promise<
|
|
NextResponse<{
|
|
total: {
|
|
hits: number;
|
|
};
|
|
pages: Array<{
|
|
slug: string;
|
|
hits: number;
|
|
}>;
|
|
}>
|
|
> => {
|
|
// note: while hits have been renamed to views in most places, this API shouldn't change due to it being snapshotted
|
|
const views = await getAllViewCounts();
|
|
|
|
const total = {
|
|
hits: Object.values(views).reduce((acc, curr) => acc + curr, 0),
|
|
};
|
|
const pages = Object.entries(views).map(([slug, views]) => ({
|
|
slug,
|
|
hits: views,
|
|
}));
|
|
|
|
pages.sort((a, b) => b.hits - a.hits);
|
|
|
|
return NextResponse.json({ total, pages });
|
|
};
|