From d5029706ad9a90a1c166347dd4f1c59a67139da6 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 23 Apr 2024 03:39:17 +0100 Subject: [PATCH] add medata for the paste page --- package.json | 1 + pnpm-lock.yaml | 7 +++++++ src/app/(pages)/[id]/page.tsx | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/package.json b/package.json index 994536c..b0ff312 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "highlight.js": "^11.9.0", "lang-detector": "^1.0.6", "lucide-react": "^0.372.0", + "moment": "^2.30.1", "next": "14.2.2", "next-themes": "^0.3.0", "react": "^18", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 21b40ec..b726ac6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ dependencies: lucide-react: specifier: ^0.372.0 version: 0.372.0(react@18.2.0) + moment: + specifier: ^2.30.1 + version: 2.30.1 next: specifier: 14.2.2 version: 14.2.2(react-dom@18.2.0)(react@18.2.0) @@ -2014,6 +2017,10 @@ packages: resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==} engines: {node: '>=16 || 14 >=14.17'} + /moment@2.30.1: + resolution: {integrity: sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==} + dev: false + /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true diff --git a/src/app/(pages)/[id]/page.tsx b/src/app/(pages)/[id]/page.tsx index 8125525..5330d46 100644 --- a/src/app/(pages)/[id]/page.tsx +++ b/src/app/(pages)/[id]/page.tsx @@ -6,6 +6,8 @@ import { ActionMenu } from "@/app/components/action-menu"; import "highlight.js/styles/github-dark-dimmed.css"; import { cn } from "@/app/common/utils"; import { jetbrainsMono } from "@/app/common/font/font"; +import { Metadata } from "next"; +import moment from "moment"; type PasteProps = { params: { @@ -19,12 +21,33 @@ type Paste = { */ content?: string; + /** + * The date the paste was created. + */ + created?: number; + /** * Whether an error occurred. */ error?: boolean; }; +export async function generateMetadata({ + params: { id }, +}: PasteProps): Promise { + const { content, created, error } = await getData(id); + + if (content == undefined || error) { + return { + description: "Not found", + }; + } + + return { + description: `Created: ${moment(created)}\n\nClick to view the paste.`, + }; +} + async function getData(id: string): Promise { const response = await fetch(`${process.env.NEXT_PUBLIC_API_ENDPOINT}/${id}`); const json = await response.json();