Fix twitter:url to use pretty URL, add trailing slash

This commit is contained in:
Obsidian Sync 2026-02-25 19:33:42 +05:30
parent 95302075ef
commit 77b33e837d

View file

@ -26,7 +26,7 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);
const pathParts = Astro.url.pathname.split('/').filter(Boolean);
const blogPostMatch = pathParts[0] === 'blog' ? pathParts[1] : pathParts[0];
const isBlogPost = blogPostMatch?.match(/^\d{4}-\d{2}-\d{2}-/);
const finalCanonicalPath = isBlogPost ? `/${blogPostMatch}` : Astro.url.pathname;
const finalCanonicalPath = isBlogPost ? `/${blogPostMatch}/` : Astro.url.pathname;
const finalCanonicalURL = new URL(finalCanonicalPath, Astro.site);
const { title, description, image = "/astro-micro.jpg" } = Astro.props;
@ -59,7 +59,7 @@ const { title, description, image = "/astro-micro.jpg" } = Astro.props;
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={Astro.url} />
<meta property="twitter:url" content={finalCanonicalURL} />
<meta property="twitter:title" content={title} />
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={new URL(image, Astro.url)} />