From 8269aa2920ee51b0076e524f5aa36f3863f94aca Mon Sep 17 00:00:00 2001 From: Tom Hackshaw <42124348+et0and@users.noreply.github.com> Date: Thu, 17 Oct 2024 22:57:11 +1300 Subject: [PATCH] Delete src/app/info/[[...slug]] directory --- src/app/info/[[...slug]]/layout.tsx | 13 ---- src/app/info/[[...slug]]/page.tsx | 111 ---------------------------- 2 files changed, 124 deletions(-) delete mode 100644 src/app/info/[[...slug]]/layout.tsx delete mode 100644 src/app/info/[[...slug]]/page.tsx diff --git a/src/app/info/[[...slug]]/layout.tsx b/src/app/info/[[...slug]]/layout.tsx deleted file mode 100644 index 01e048d..0000000 --- a/src/app/info/[[...slug]]/layout.tsx +++ /dev/null @@ -1,13 +0,0 @@ -export default function InfoLayout({ - children, -}: { - children: React.ReactNode; -}) { - return ( -
-
-
{children}
-
-
- ); -} diff --git a/src/app/info/[[...slug]]/page.tsx b/src/app/info/[[...slug]]/page.tsx deleted file mode 100644 index a2c60ef..0000000 --- a/src/app/info/[[...slug]]/page.tsx +++ /dev/null @@ -1,111 +0,0 @@ -import prisma from "@/lib/prisma"; -import redis from "@/lib/redis"; -import { Separator } from "@/components/ui/separator/separator"; -import { Metadata } from "next"; - -async function getPageViews(path: string) { - const cacheKey = `pageviews:${path}`; - - // Try to get data from cache - const cachedData = await redis.get(cacheKey); - if (cachedData !== null) { - return JSON.parse(cachedData as string); - } - - try { - const [totalPageViews, last30DaysViews, viewsOverTime] = await Promise.all([ - prisma.pageView.count({ - where: { pagePath: path, filtered: false }, - }), - prisma.pageView.count({ - where: { - pagePath: path, - filtered: false, - timestamp: { gte: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000) }, - }, - }), - prisma.$queryRaw>` - SELECT DATE_TRUNC('month', timestamp) as date, COUNT(*) as count - FROM "PageView" - WHERE "pagePath" = ${path} AND filtered = false - GROUP BY DATE_TRUNC('month', timestamp) - ORDER BY date ASC - `, - ]); - - const result = { - totalPageViews, - last30DaysViews, - viewsOverTime: viewsOverTime.map(({ date, count }) => ({ - date: date.toISOString().slice(0, 7), - count: Number(count), - })), - }; - - // Cache the result for 5 minutes - await redis.set(cacheKey, JSON.stringify(result), { ex: 300 }); - - return result; - } catch (error) { - console.error("Error fetching page views:", error); - return null; - } -} - -export async function generateMetadata({ - params, -}: { - params: { slug?: string[] }; -}): Promise { - const path = params.slug ? `/${params.slug.join("/")}` : "/"; - - return { - title: `Analytics for ${path}`, - description: `Total views for ${path}`, - }; -} - -export const revalidate = 3600; // revalidate every hour - -export default async function InfoPage({ - params, -}: { - params: { slug?: string[] }; -}) { - const path = params.slug ? `/${params.slug.join("/")}` : "/"; - - const pageViews = await getPageViews(path); - - if (!pageViews) { - return
Error loading page views. Please try again later.
; - } - - return ( -
-

Analytics for {path}

- - - {pageViews.totalPageViews === 0 ? ( -

No views recorded for this page yet.

- ) : ( - <> -

Total views to date: {pageViews.totalPageViews}

-

Breakdown

-
    - {pageViews.viewsOverTime.map( - ({ date, count }: { date: string; count: number }) => ( -
  • - {new Date(date).toLocaleString("default", { - month: "long", - year: "numeric", - })} - : {count} views -
  • - ), - )} -
- - )} -
- ); -} \ No newline at end of file