@@ -9,9 +9,12 @@ import { SITE_NAME } from "@/lib/site";
99 */
1010interface Props {
1111 title: string ;
12+ ogTitle? : string | null ;
1213 description? : string | null ;
14+ ogDescription? : string | null ;
1315 image? : { url: string ; alt? : string ; width? : number ; height? : number } | null ;
1416 type? : " website" | " article" ;
17+ twitterCard? : string | null ;
1518 publishedAt? : string | null ;
1619 modifiedAt? : string | null ;
1720 authors? : Array <string | null | undefined >;
@@ -21,16 +24,27 @@ interface Props {
2124
2225const {
2326 title,
27+ ogTitle,
2428 description,
29+ ogDescription,
2530 image,
2631 type = " website" ,
32+ twitterCard,
2733 publishedAt,
2834 modifiedAt,
2935 authors = [],
3036 canonical = Astro .url ,
3137 noindex = false ,
3238} = Astro .props ;
3339
40+ function cleanMetaText(value : string | null | undefined ): string | undefined {
41+ const cleaned = stegaClean (value )?.trim ();
42+ if (! cleaned || cleaned .toLowerCase () === " fix me" ) {
43+ return undefined ;
44+ }
45+ return cleaned ;
46+ }
47+
3448// Per-request, not `Astro.site`: the origin differs between the dev and
3549// production Workers but the build is shared.
3650const site = Astro .locals .siteUrl ;
@@ -39,9 +53,18 @@ const canonicalUrl = new URL(
3953 site ,
4054).href ;
4155
42- const cleanTitle = stegaClean (title ) ?? SITE_NAME ;
43- const cleanDescription = stegaClean (description ) ?? undefined ;
56+ const cleanTitle = cleanMetaText (title ) ?? SITE_NAME ;
57+ const cleanOgTitle = cleanMetaText (ogTitle ) ?? cleanTitle ;
58+ const cleanDescription = cleanMetaText (description );
59+ const cleanOgDescription = cleanMetaText (ogDescription ) ?? cleanDescription ;
4460const imageUrl = image ?.url ? new URL (stegaClean (image .url ), site ).href : undefined ;
61+ const imageAlt = cleanMetaText (image ?.alt ) ?? cleanOgTitle ;
62+ const cardType =
63+ cleanMetaText (twitterCard ) === " summary"
64+ ? " summary"
65+ : imageUrl
66+ ? " summary_large_image"
67+ : " summary" ;
4568---
4669
4770<title >{ cleanTitle } </title >
@@ -50,26 +73,34 @@ const imageUrl = image?.url ? new URL(stegaClean(image.url), site).href : undefi
5073{ noindex && <meta name = " robots" content = " noindex, nofollow" />}
5174
5275<meta property =" og:site_name" content ={ SITE_NAME } />
76+ <meta property =" og:locale" content =" en_US" />
5377<meta property =" og:type" content ={ type } />
54- <meta property =" og:title" content ={ cleanTitle } />
55- { cleanDescription && <meta property = " og:description" content = { cleanDescription } />}
78+ <meta property =" og:title" content ={ cleanOgTitle } />
79+ { cleanOgDescription && <meta property = " og:description" content = { cleanOgDescription } />}
5680<meta property =" og:url" content ={ canonicalUrl } />
5781{
5882 imageUrl && (
5983 <>
6084 <meta property = " og:image" content = { imageUrl } />
6185 { image ?.width && <meta property = " og:image:width" content = { String (image .width )} />}
6286 { image ?.height && <meta property = " og:image:height" content = { String (image .height )} />}
63- { image ?. alt && <meta property = " og:image:alt" content = { stegaClean ( image . alt ) } />}
87+ { imageAlt && <meta property = " og:image:alt" content = { imageAlt } />}
6488 </>
6589 )
6690}
6791
68- <meta name =" twitter:card" content ={ imageUrl ? " summary_large_image " : " summary " } />
92+ <meta name =" twitter:card" content ={ cardType } />
6993<meta name =" twitter:site" content =" @CodingCatDev" />
70- <meta name =" twitter:title" content ={ cleanTitle } />
71- { cleanDescription && <meta name = " twitter:description" content = { cleanDescription } />}
72- { imageUrl && <meta name = " twitter:image" content = { imageUrl } />}
94+ <meta name =" twitter:title" content ={ cleanOgTitle } />
95+ { cleanOgDescription && <meta name = " twitter:description" content = { cleanOgDescription } />}
96+ {
97+ imageUrl && (
98+ <>
99+ <meta name = " twitter:image" content = { imageUrl } />
100+ { imageAlt && <meta name = " twitter:image:alt" content = { imageAlt } />}
101+ </>
102+ )
103+ }
73104
74105{
75106 type === " article" && (
0 commit comments