Helper function to define a template with type safety. Use this when creating custom templates for your Open Graph images.
Function Signature
function defineTemplate<T extends OgTemplateParams>(
config: TemplateConfig<T>
): OgTemplate<T>;
Parameters
Template configuration
Function that returns an HTML string. Receives { params, isRTL }(context: { params: T; isRTL: boolean }) => string
Array of font definitions required by the template
Emoji provider to use. Options: 'twemoji', 'fluent', 'fluentFlat', 'noto', 'blobmoji', 'openmoji'
Returns
The defined template object that can be used with createRenderer
Example
import { defineTemplate } from "@ogify/core";
export type MyTemplateParams = {
title: string;
description: string;
};
const myTemplate = defineTemplate<MyTemplateParams>({
fonts: [
{ name: "Inter", weight: 400 },
{ name: "Inter", weight: 700 },
],
emojiProvider: "twemoji",
renderer: ({ params, isRTL }) => {
return `
<div style="display: flex; width: 100%; height: 100%; direction: ${
isRTL ? "rtl" : "ltr"
};">
<h1>${params.title}</h1>
<p>${params.description}</p>
</div>
`;
},
});
export default myTemplate;