feat: add structured product metadata
This commit is contained in:
2 files changed
+67
-4
No files matched your search
+36
-3
@@ -3,20 +3,40 @@ import Header from '../components/Header.astro';
|
||||
import Footer from '../components/Footer.astro';
|
||||
import '../styles/global.css';
|
||||
|
||||
type OpenGraphType = 'website' | 'article';
|
||||
type StructuredData = Record<string, unknown>;
|
||||
|
||||
interface Props {
|
||||
title?: string;
|
||||
description?: string;
|
||||
image?: string;
|
||||
ogType?: OpenGraphType;
|
||||
robots?: string;
|
||||
publishedTime?: Date;
|
||||
updatedTime?: Date;
|
||||
author?: string;
|
||||
tags?: string[];
|
||||
structuredData?: StructuredData;
|
||||
}
|
||||
|
||||
const {
|
||||
title = 'Green Tea — A zen, type-safe graph-pipeline HTTP framework',
|
||||
description = 'Green Tea is a graph-pipeline HTTP framework: declare what you need, not the order to build it. Runtime-agnostic, type-safe, calm by design.',
|
||||
image = '/og.png',
|
||||
ogType = 'website',
|
||||
robots = 'index, follow',
|
||||
publishedTime,
|
||||
updatedTime,
|
||||
author,
|
||||
tags,
|
||||
structuredData,
|
||||
} = Astro.props;
|
||||
|
||||
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
|
||||
const ogImageURL = new URL(image, Astro.site);
|
||||
const canonicalURL = new URL(Astro.url.pathname, Astro.site).toString();
|
||||
const ogImageURL = new URL(image, Astro.site).toString();
|
||||
const serializedStructuredData = structuredData
|
||||
? JSON.stringify(structuredData).replace(/</g, '\\u003c')
|
||||
: undefined;
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
@@ -29,13 +49,24 @@ const ogImageURL = new URL(image, Astro.site);
|
||||
|
||||
<title>{title}</title>
|
||||
<meta name="description" content={description} />
|
||||
<meta name="robots" content={robots} />
|
||||
|
||||
<!-- Open Graph -->
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:type" content={ogType} />
|
||||
<meta property="og:url" content={canonicalURL} />
|
||||
<meta property="og:title" content={title} />
|
||||
<meta property="og:description" content={description} />
|
||||
<meta property="og:image" content={ogImageURL} />
|
||||
{
|
||||
ogType === 'article' && (
|
||||
<>
|
||||
{publishedTime && <meta property="article:published_time" content={publishedTime.toISOString()} />}
|
||||
{updatedTime && <meta property="article:modified_time" content={updatedTime.toISOString()} />}
|
||||
{author && <meta property="article:author" content={author} />}
|
||||
{tags?.map((tag) => <meta property="article:tag" content={tag} />)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
<!-- Twitter -->
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
@@ -43,6 +74,8 @@ const ogImageURL = new URL(image, Astro.site);
|
||||
<meta name="twitter:description" content={description} />
|
||||
<meta name="twitter:image" content={ogImageURL} />
|
||||
|
||||
{serializedStructuredData && <script type="application/ld+json" set:html={serializedStructuredData} />}
|
||||
|
||||
<!-- RSS -->
|
||||
<link rel="alternate" type="application/rss+xml" title="Green Tea. Blog" href="/rss.xml" />
|
||||
|
||||
|
||||
Reference in new issue
Block a user