mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-19 13:55:31 -04:00
extract metadata merging logic from each page into a helper function
This commit is contained in:
29
lib/helpers/metadata.ts
Normal file
29
lib/helpers/metadata.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import defaultMetadata from "../config/metadata";
|
||||
import type { Metadata } from "next";
|
||||
|
||||
// helper function to deep merge a page's metadata into the default site 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,
|
||||
},
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user