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

View File

@ -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();