Skip to content

Commit

Permalink
feat: add support for OG article tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasmerlin committed Sep 25, 2021
1 parent 875d910 commit 9615bfa
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/SEO.astro
Expand Up @@ -37,6 +37,14 @@ export interface Props {
width?: number;
height?: number;
alt?: string;
},
article?: {
publishedTime?: string;
modifiedTime?: string;
expirationTime?: string;
authors?: string[];
section?: string;
tags?: string[];
}
},
twitter?: {
Expand Down Expand Up @@ -111,6 +119,46 @@ function generateOpenGraphImageTags(props: Props) {
}
}
function generateOpenGraphArticleTags(props: Props) {
if (props.openGraph?.article) {
const {
publishedTime,
modifiedTime,
expirationTime,
authors,
section,
tags
} = props.openGraph.article;
return (
<Fragment>
{ publishedTime ? (
<meta property="article:published_time" content={publishedTime} />
) : null}
{ modifiedTime ? (
<meta property="article:modified_time" content={modifiedTime} />
) : null}
{ expirationTime ? (
<meta property="article:expiration_time" content={expirationTime} />
) : null}
{ authors ? (
authors.map((author) => (
<meta property="article:author" content={author} />
))
) : null}
{ section ? (
<meta property="article:section" content={section} />
) : null}
{ tags ? (
tags.map((tag) => (
<meta property="article:tag" content={tag} />
))
) : null}
</Fragment>
)
}
}
function generateTwitterTags(props: Props) {
if (props.twitter) {
const {
Expand Down Expand Up @@ -192,4 +240,6 @@ function generateTwitterTags(props: Props) {
) : null }

{generateOpenGraphImageTags(props)}
{generateOpenGraphArticleTags(props)}
{generateTwitterTags(props)}

0 comments on commit 9615bfa

Please sign in to comment.