-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSocialMeta.astro
More file actions
58 lines (51 loc) · 1.7 KB
/
SocialMeta.astro
File metadata and controls
58 lines (51 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
interface Props {
title: string;
description?: string;
ogImage?: string;
type?: 'website' | 'article';
publishedAt?: string;
author?: string;
canonicalUrl?: string;
}
const {
title,
description = "CodingCat.dev — Purrfect Web Tutorials",
ogImage,
type = "website",
publishedAt,
author,
canonicalUrl,
} = Astro.props;
const siteUrl = Astro.url.origin;
const resolvedUrl = canonicalUrl || Astro.url.href;
const resolvedImage = ogImage || `${siteUrl}/api/og/default.png?title=${encodeURIComponent(title)}`;
---
{/* Primary Meta Tags */}
<meta name="description" content={description} />
{/* Canonical */}
{canonicalUrl && <link rel="canonical" href={canonicalUrl} />}
{/* Open Graph */}
<meta property="og:type" content={type} />
<meta property="og:url" content={resolvedUrl} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={resolvedImage} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta property="og:image:alt" content={title} />
<meta property="og:site_name" content="CodingCat.dev" />
<meta property="og:locale" content="en_US" />
{/* Twitter Card */}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@codingcatdev" />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta name="twitter:image" content={resolvedImage} />
{/* Article-specific */}
{type === "article" && publishedAt && (
<meta property="article:published_time" content={publishedAt} />
)}
{type === "article" && author && (
<meta property="article:author" content={author} />
)}