Skip to content

Commit dc84f1d

Browse files
committed
Fix the error about title
1 parent a153eeb commit dc84f1d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/components/BaseHead.astro

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
import "@/styles/globals.css";
3-
import { getCollection } from 'astro:content';
3+
import { getEntryBySlug } from 'astro:content';
44
import { CONFIG } from "@/config";
55
66
export type Props = {
@@ -16,16 +16,16 @@ const {
1616
pageType = "website",
1717
} = Astro.props;
1818
19-
const posts = await getCollection('blog');
19+
const getTitle = async (slug) => {
20+
if (Astro.props.title) return Astro.props.title;
2021
21-
const getTitle = (slug) => {
22-
const post = posts.find((p) => p.slug === slug);
23-
return post?.data.title || null; // Return null if not found
22+
if (!slug) return CONFIG.meta.title; // Fallback if no slug is provided
23+
24+
const post = await getEntryBySlug('blog', slug);
25+
return post?.data.title || CONFIG.meta.title;
2426
};
2527
26-
const title = [getTitle(Astro.params.slug), Astro.props.title, CONFIG.meta.title]
27-
.filter(Boolean)
28-
.join(" | ");
28+
const title = await getTitle(Astro.params?.slug);
2929
3030
const resolvedImage = image?.src
3131
? {

0 commit comments

Comments
 (0)