Skip to content

Commit

Permalink
feat: add published_time & modified_time meta tags
Browse files Browse the repository at this point in the history
  • Loading branch information
satnaing committed Dec 21, 2023
1 parent 8ddd9f5 commit c02b812
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface Props {
description?: string;
ogImage?: string;
canonicalURL?: string;
pubDatetime?: Date;
modDatetime?: Date;
}
const {
Expand All @@ -19,6 +21,8 @@ const {
description = SITE.desc,
ogImage = SITE.ogImage,
canonicalURL = new URL(Astro.url.pathname, Astro.site).href,
pubDatetime,
modDatetime,
} = Astro.props;
const socialImageURL = new URL(
Expand Down Expand Up @@ -49,6 +53,24 @@ const socialImageURL = new URL(
<meta property="og:url" content={canonicalURL} />
<meta property="og:image" content={socialImageURL} />

<!-- Article Published/Modified time -->
{
pubDatetime && (
<meta
property="article:published_time"
content={pubDatetime.toISOString()}
/>
)
}
{
modDatetime && (
<meta
property="article:modified_time"
content={modDatetime.toISOString()}
/>
)
}

<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={canonicalURL} />
Expand Down
2 changes: 2 additions & 0 deletions src/layouts/PostDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const layoutProps = {
title,
author,
description,
pubDatetime,
modDatetime,
canonicalURL,
ogImage: ogUrl,
};
Expand Down

0 comments on commit c02b812

Please sign in to comment.