diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index 68e3d97..3b12c8b 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -5,8 +5,9 @@ interface Props { image?: string; } -import { withBase } from "../lib/utils"; -const { title, description = "The official blog of the Python core development team.", image } = Astro.props; +import { withBase, stripDescriptionLinks } from "../lib/utils"; +const { title, description: rawDescription = "The official blog of the Python core development team.", image } = Astro.props; +const description = stripDescriptionLinks(rawDescription); const baseUrl = import.meta.env.DEV ? Astro.url.origin : Astro.site; const canonicalURL = new URL(Astro.url.pathname, Astro.site); const ogImage = image ? new URL(image, baseUrl) : new URL(withBase("/og-default.png"), baseUrl); diff --git a/src/components/BlogPostCard.astro b/src/components/BlogPostCard.astro index f302c10..7712434 100644 --- a/src/components/BlogPostCard.astro +++ b/src/components/BlogPostCard.astro @@ -1,5 +1,5 @@ --- -import { formatDate, postUrl, slugify, withBase } from "../lib/utils"; +import { formatDate, postUrl, slugify, withBase, renderDescriptionLinks } from "../lib/utils"; interface Props { slug: string; @@ -29,7 +29,7 @@ const { slug, title, publishDate, author, description, tags, showEditLink = true {description && ( -

{description}

+

)} {tags && tags.length > 0 && (

diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 5d68915..116ccbc 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -34,6 +34,23 @@ export function postUrl(slug: string, publishDate: string | Date): string { return `/${year}/${month}/${slug}`; } +/** + * Converts markdown-style links [text](url) in a description to HTML anchor tags. + */ +export function renderDescriptionLinks(desc: string): string { + return desc.replace( + /\[([^\]]+)\]\(([^)]+)\)/g, + '$1', + ); +} + +/** + * Strips markdown-style links [text](url) to plain text for meta tags. + */ +export function stripDescriptionLinks(desc: string): string { + return desc.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1"); +} + export function slugify(text: string): string { return text .normalize("NFD") diff --git a/src/pages/index.astro b/src/pages/index.astro index 88c714e..7f245c6 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -3,7 +3,7 @@ export const prerender = true; import BaseLayout from "../layouts/BaseLayout.astro"; import PythonLogo from "../components/PythonLogo.astro"; -import { formatDate, postUrl, withBase } from "../lib/utils"; +import { formatDate, postUrl, withBase, renderDescriptionLinks } from "../lib/utils"; import { getCollection } from "astro:content"; const allPosts = await getCollection("posts"); @@ -66,9 +66,7 @@ const authors = new Set(posts.map((p) => p.data.author));
{featured.data.description && ( -

- {featured.data.description} -

+

)} @@ -132,7 +130,7 @@ const authors = new Set(posts.map((p) => p.data.author)); {post.data.description && ( -

{post.data.description}

+

)} ))}