Skip to content

Commit a153eeb

Browse files
committed
Fix HTML title of blog posts
1 parent f05fa89 commit a153eeb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/components/BaseHead.astro

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
import "@/styles/globals.css";
3+
import { getCollection } from 'astro:content';
34
import { CONFIG } from "@/config";
45
56
export type Props = {
@@ -14,9 +15,18 @@ const {
1415
image = CONFIG.meta.image,
1516
pageType = "website",
1617
} = Astro.props;
17-
const title = [Astro.props.title, CONFIG.meta.title]
18-
.filter(Boolean)
19-
.join(" | ");
18+
19+
const posts = await getCollection('blog');
20+
21+
const getTitle = (slug) => {
22+
const post = posts.find((p) => p.slug === slug);
23+
return post?.data.title || null; // Return null if not found
24+
};
25+
26+
const title = [getTitle(Astro.params.slug), Astro.props.title, CONFIG.meta.title]
27+
.filter(Boolean)
28+
.join(" | ");
29+
2030
const resolvedImage = image?.src
2131
? {
2232
src: new URL(image.src, Astro.site).toString(),

0 commit comments

Comments
 (0)