Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions content-collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ const posts = defineCollection({
}),
transform: ({ content, ...post }) => {
const frontMatter = extractFrontMatter(content)

// Extract header image (first image after frontmatter)
const headerImageMatch = content.match(/!\[([^\]]*)\]\(([^)]+)\)/)
const headerImage = headerImageMatch ? headerImageMatch[2] : undefined

return {
...post,
slug: post._meta.path,
excerpt: frontMatter.excerpt,
description: frontMatter.data.description,
headerImage,
content,
}
},
Expand Down
13 changes: 13 additions & 0 deletions src/routes/_libraries/blog.$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const fetchBlogPost = createServerFn({ method: 'GET' })
published: post.published,
content: post.content,
authors: post.authors,
headerImage: post.headerImage,
filePath,
}
})
Expand All @@ -68,12 +69,24 @@ export const Route = createFileRoute('/_libraries/blog/$')({
staleTime: Infinity,
loader: ({ params }) => fetchBlogPost({ data: params._splat }),
head: ({ loaderData }) => {
// Generate optimized social media image URL using Netlify Image CDN
const getSocialImageUrl = (headerImage?: string) => {
if (!headerImage) return undefined

// Use Netlify Image CDN to optimize for social media (1200x630 is the standard for og:image)
const netlifyImageUrl = `https://tanstack.com/.netlify/images?url=${encodeURIComponent(
headerImage
)}&w=1200&h=630&fit=cover&fm=jpg&q=80`
return netlifyImageUrl
}

return {
meta: loaderData
? [
...seo({
title: `${loaderData?.title ?? 'Docs'} | TanStack Blog`,
description: loaderData?.description,
image: getSocialImageUrl(loaderData?.headerImage),
}),
{
name: 'author',
Expand Down
Loading