--- import PageShell from '../../components/PageShell.astro'; import { getCollection, render } from 'astro:content'; export async function getStaticPaths() { const posts = await getCollection('blog', ({ data }) => !data.draft); return posts.map((post) => ({ params: { slug: post.id }, props: { post }, })); } const { post } = Astro.props; const { Content } = await render(post); const siteUrl = new URL('/', Astro.site).toString(); // --- Date formatting --- const formattedDate = new Intl.DateTimeFormat('th-TH', { dateStyle: 'long', }).format(post.data.pubDate); // --- Image: og_image > heroImage > default logo --- const ogImage = new URL( post.data.og_image || post.data.heroImage || '/images/logos/logo-long-black.png', Astro.site, ).toString(); // --- FAQPage auto-extraction --- const rawBody = post.body || ''; const faqSectionRegex = /##\s*คำถามที่พบบ่อย\s*\n([\s\S]*?)(?=##\s|\Z)/; const faqMatch = rawBody.match(faqSectionRegex); const faqPairs: { question: string; answer: string }[] = faqMatch ? [...faqMatch[1].matchAll(/###\s+(.+?)\n\s*\n?(.+?)(?=\n###|\Z)/gs)] .map(([, q, a]) => ({ question: q.trim(), answer: a.trim() })) : []; // --- Escaped body for JSON-LD safety --- const safeBody = rawBody.replace(/<\//g, '<\\/'); // --- BlogPosting JSON-LD --- const blogPostingJsonLd = JSON.stringify({ '@context': 'https://schema.org', '@id': `${siteUrl}blog/${post.id}/#blogposting`, '@type': 'BlogPosting', headline: post.data.title, description: post.data.description, datePublished: post.data.pubDate.toISOString(), dateModified: (post.data.updatedDate || post.data.pubDate).toISOString(), ...(post.data.author && { author: { '@type': 'Person', name: post.data.author }, }), ...(post.data.reviewer && { reviewedBy: { '@type': 'Person', name: post.data.reviewer }, }), publisher: { '@id': `${siteUrl}#organization`, '@type': 'Organization', name: 'MoreminiMore', logo: { '@type': 'ImageObject', url: new URL('/images/logos/logo-long-black.png', Astro.site).toString(), }, }, mainEntityOfPage: new URL(`/blog/${post.id}/`, Astro.site).toString(), articleBody: safeBody, }); // --- BreadcrumbList JSON-LD --- const breadcrumbJsonLd = JSON.stringify({ '@context': 'https://schema.org', '@id': `${siteUrl}blog/${post.id}/#breadcrumb`, '@type': 'BreadcrumbList', itemListElement: [ { '@type': 'ListItem', position: 1, name: 'บทความ', item: new URL('/blog/', Astro.site).toString(), }, { '@type': 'ListItem', position: 2, name: post.data.title, }, ], }); // --- FAQPage JSON-LD --- const faqPageJsonLd = faqPairs.length > 0 ? JSON.stringify({ '@context': 'https://schema.org', '@id': `${siteUrl}blog/${post.id}/#faq`, '@type': 'FAQPage', mainEntity: faqPairs.map(({ question, answer }) => ({ '@type': 'Question', name: question, acceptedAnswer: { '@type': 'Answer', text: answer, }, })), }) : ''; --- {faqPageJsonLd && ( )}
← บทความทั้งหมด

{post.data.title}

{post.data.description}

{post.data.title}