diff --git a/src/views/meta.ts b/src/views/meta.ts new file mode 100644 index 00000000..f4f2b470 --- /dev/null +++ b/src/views/meta.ts @@ -0,0 +1,36 @@ +import { html } from '@/utils/html.ts'; +import { OpenGraphTemplateOpts } from '@/utils/og-metadata.ts'; + +/** + * Builds a series of meta tags from supplied metadata for injection into the served HTML page. + * @param opts the metadata to use to fill the template. + * @returns the built OpenGraph metadata. + */ +export const metadataView = ({ title, type, url, image, description, site }: OpenGraphTemplateOpts): string => { + const res = []; + res.push(html`\ + + + + + + + + + `); + + if (image) { + res.push(html`\ + + + + + `); + if (image.alt) { + res.push(html``); + res.push(html``); + } + } + + return res.join('\n').replace(/\n+/g, '\n').replace(/^[ ]+/gm, ''); +};