add medata for the paste page
All checks were successful
Deploy App / docker (ubuntu-latest) (push) Successful in 2m8s
Publish Docker Image / docker (ubuntu-latest) (push) Successful in 1m35s

This commit is contained in:
Lee 2024-04-23 03:39:17 +01:00
parent cefa5fefe8
commit d5029706ad
3 changed files with 31 additions and 0 deletions

@ -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",

@ -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

@ -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<Metadata> {
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<Paste> {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_ENDPOINT}/${id}`);
const json = await response.json();