File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 11---
22import " @/styles/globals.css" ;
3- import { getCollection } from ' astro:content' ;
3+ import { getEntryBySlug } from ' astro:content' ;
44import { CONFIG } from " @/config" ;
55
66export 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
3030const resolvedImage = image ?.src
3131 ? {
You can’t perform that action at this time.
0 commit comments