2023-12-27 12:19:03 +00:00
|
|
|
import OGImage from "../images/og_default.png";
|
2023-12-27 16:20:55 +00:00
|
|
|
import type {
|
|
|
|
ServerRuntimeMetaArgs,
|
|
|
|
ServerRuntimeMetaDescriptor,
|
|
|
|
} from "@remix-run/server-runtime";
|
2023-12-27 12:19:03 +00:00
|
|
|
|
2023-12-27 16:20:55 +00:00
|
|
|
interface GenerateMetaTagsParams {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
imageUrl?: {};
|
|
|
|
ogType?: "website" | "article";
|
|
|
|
parentMeta?: ServerRuntimeMetaArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function generateMetaTags({
|
|
|
|
title,
|
|
|
|
description,
|
2023-12-27 12:19:03 +00:00
|
|
|
imageUrl = OGImage,
|
2023-12-27 16:20:55 +00:00
|
|
|
ogType = "website",
|
|
|
|
parentMeta,
|
|
|
|
}: GenerateMetaTagsParams) {
|
|
|
|
let parentMetaMerged: ServerRuntimeMetaDescriptor[] = [];
|
|
|
|
|
|
|
|
if (parentMeta?.matches) {
|
|
|
|
parentMetaMerged = parentMeta?.matches.flatMap((match) => match.meta ?? []);
|
|
|
|
}
|
|
|
|
|
2023-12-27 12:19:03 +00:00
|
|
|
return [
|
2023-12-27 16:20:55 +00:00
|
|
|
...parentMetaMerged,
|
2023-12-27 15:43:22 +00:00
|
|
|
{ title },
|
2023-12-27 12:19:03 +00:00
|
|
|
{ name: "title", content: title },
|
|
|
|
{ name: "description", content: description },
|
|
|
|
{ name: "og:title", content: title },
|
|
|
|
{ name: "og:description", content: description },
|
|
|
|
{ name: "og:image", content: imageUrl },
|
|
|
|
{ name: "og:type", content: ogType },
|
|
|
|
];
|
|
|
|
}
|