From 5785f070526efbb8e5f62d0e440c3dbfe780114e Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Mon, 5 Aug 2024 20:02:03 +0530 Subject: [PATCH] tpl --> metadataView --- src/views/meta.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/views/meta.ts 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, ''); +};