1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-26 03:25:23 -04:00
jarv.is/lib/helpers/metadata.ts

76 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import * as config from "../config";
import { BASE_URL } from "../config/constants";
import type { Metadata } from "next";
export const defaultMetadata: Metadata = {
metadataBase: new URL(BASE_URL),
title: {
template: `%s ${config.siteName}`,
default: `${config.siteName} ${config.shortDescription}`,
},
description: config.longDescription,
openGraph: {
siteName: config.siteName,
title: {
template: "%s",
default: `${config.siteName} ${config.shortDescription}`,
},
url: "/",
locale: config.siteLocale?.replace("-", "_"),
type: "website",
},
twitter: {
creator: `@${config.authorSocial?.twitter}`,
},
alternates: {
canonical: "/",
types: {
"application/rss+xml": [
{
title: `${config.siteName} (RSS)`,
url: "/feed.xml",
},
],
"application/atom+xml": [
{
title: `${config.siteName} (Atom)`,
url: "/feed.atom",
},
],
},
},
other: {
humans: "/humans.txt",
},
};
/**
* Helper function to deep merge a page's metadata into the default site metadata
* @see https://nextjs.org/docs/app/api-reference/functions/generate-metadata
*/
export const addMetadata = (metadata: Metadata): Metadata => {
return {
...defaultMetadata,
...metadata,
openGraph: {
...defaultMetadata.openGraph,
title: metadata.title as string,
description: metadata.description as string,
url: metadata.alternates?.canonical as string,
...metadata.openGraph,
},
twitter: {
...defaultMetadata.twitter,
...metadata.twitter,
},
alternates: {
...defaultMetadata.alternates,
...metadata.alternates,
},
other: {
...defaultMetadata.other,
...metadata.other,
},
};
};