mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
tpl --> metadataView
This commit is contained in:
parent
c7e5aed679
commit
5785f07052
1 changed files with 36 additions and 0 deletions
36
src/views/meta.ts
Normal file
36
src/views/meta.ts
Normal file
|
|
@ -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`\
|
||||
<meta content="${title}" property="og:title">
|
||||
<meta content="${type}" property="og:type">
|
||||
<meta content="${url}" property="og:url">
|
||||
<meta content="${description}" property="og:description">
|
||||
<meta content="${site}" property="og:site_name">
|
||||
<meta name="twitter:card" content="summary">
|
||||
<meta name="twitter:title" content="${title}">
|
||||
<meta name="twitter:description" content="${description}">
|
||||
`);
|
||||
|
||||
if (image) {
|
||||
res.push(html`\
|
||||
<meta content="${image.url}" property="og:image">
|
||||
<meta content="${image.w}" property="og:image:width">
|
||||
<meta content="${image.h}" property="og:image:height">
|
||||
<meta name="twitter:image" content="${image.url}">
|
||||
`);
|
||||
if (image.alt) {
|
||||
res.push(html`<meta content="${image.alt}" property="og:image:alt">`);
|
||||
res.push(html`<meta content="${image.alt}" property="twitter:image:alt">`);
|
||||
}
|
||||
}
|
||||
|
||||
return res.join('\n').replace(/\n+/g, '\n').replace(/^[ ]+/gm, '');
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue