add medata for the paste page
This commit is contained in:
parent
cefa5fefe8
commit
d5029706ad
@ -16,6 +16,7 @@
|
|||||||
"highlight.js": "^11.9.0",
|
"highlight.js": "^11.9.0",
|
||||||
"lang-detector": "^1.0.6",
|
"lang-detector": "^1.0.6",
|
||||||
"lucide-react": "^0.372.0",
|
"lucide-react": "^0.372.0",
|
||||||
|
"moment": "^2.30.1",
|
||||||
"next": "14.2.2",
|
"next": "14.2.2",
|
||||||
"next-themes": "^0.3.0",
|
"next-themes": "^0.3.0",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@ -26,6 +26,9 @@ dependencies:
|
|||||||
lucide-react:
|
lucide-react:
|
||||||
specifier: ^0.372.0
|
specifier: ^0.372.0
|
||||||
version: 0.372.0(react@18.2.0)
|
version: 0.372.0(react@18.2.0)
|
||||||
|
moment:
|
||||||
|
specifier: ^2.30.1
|
||||||
|
version: 2.30.1
|
||||||
next:
|
next:
|
||||||
specifier: 14.2.2
|
specifier: 14.2.2
|
||||||
version: 14.2.2(react-dom@18.2.0)(react@18.2.0)
|
version: 14.2.2(react-dom@18.2.0)(react@18.2.0)
|
||||||
@ -2014,6 +2017,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==}
|
resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==}
|
||||||
engines: {node: '>=16 || 14 >=14.17'}
|
engines: {node: '>=16 || 14 >=14.17'}
|
||||||
|
|
||||||
|
/moment@2.30.1:
|
||||||
|
resolution: {integrity: sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/ms@2.1.2:
|
/ms@2.1.2:
|
||||||
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
||||||
dev: true
|
dev: true
|
||||||
|
@ -6,6 +6,8 @@ import { ActionMenu } from "@/app/components/action-menu";
|
|||||||
import "highlight.js/styles/github-dark-dimmed.css";
|
import "highlight.js/styles/github-dark-dimmed.css";
|
||||||
import { cn } from "@/app/common/utils";
|
import { cn } from "@/app/common/utils";
|
||||||
import { jetbrainsMono } from "@/app/common/font/font";
|
import { jetbrainsMono } from "@/app/common/font/font";
|
||||||
|
import { Metadata } from "next";
|
||||||
|
import moment from "moment";
|
||||||
|
|
||||||
type PasteProps = {
|
type PasteProps = {
|
||||||
params: {
|
params: {
|
||||||
@ -19,12 +21,33 @@ type Paste = {
|
|||||||
*/
|
*/
|
||||||
content?: string;
|
content?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date the paste was created.
|
||||||
|
*/
|
||||||
|
created?: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether an error occurred.
|
* Whether an error occurred.
|
||||||
*/
|
*/
|
||||||
error?: boolean;
|
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> {
|
async function getData(id: string): Promise<Paste> {
|
||||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_ENDPOINT}/${id}`);
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_ENDPOINT}/${id}`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
Reference in New Issue
Block a user