refactor: move blog from EmDash to Astro content collections
EmDash CMS integration is being removed. The blog content is
moved to native Astro content collections (markdown files in
src/content/blog/) which works with the static output config.
Changes:
- Remove EmDash from astro.config.mjs (revert to static output)
- Remove emdash packages from package.json/package-lock.json
- Remove seed/seed.json (was EmDash-only)
- Remove src/live.config.ts (EmDash Astro loader)
- Add src/content.config.ts (Astro content collection for blog)
- Move 3 blog posts to src/content/blog/*.md
- Update src/pages/index.astro to use getCollection('blog')
- Update src/pages/บทความ/[slug].astro to use render() from astro:content
(Astro 6 API: render(article), not article.render())
- Update src/pages/บทความ/index.astro (blog list)
- Add .hermes/ to .gitignore
Verified:
- npm run build: 35 pages, complete in 2.50s
- / , /aeroflex, /about-us, /บทความ, /บทความ/welcome-post: all 200
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
---
|
||||
import BaseLayout from '@/layouts/BaseLayout.astro';
|
||||
import { getEmDashCollection } from 'emdash';
|
||||
import { getCollection } from 'astro:content';
|
||||
|
||||
const { entries: articles, cacheHint } = await getEmDashCollection('blog', {
|
||||
limit: 3,
|
||||
orderBy: { published_at: 'desc' },
|
||||
status: 'published',
|
||||
});
|
||||
Astro.cache.set(cacheHint);
|
||||
const articles = (await getCollection('blog')).sort(
|
||||
(a, b) => b.data.published_at.getTime() - a.data.published_at.getTime()
|
||||
).slice(0, 3);
|
||||
---
|
||||
|
||||
<BaseLayout title="ดีล พลัส เทค - ระบบน้ำคุณภาพสูง ราคาโรงงาน" description="ดีล พลัส เทค จำกัด ผู้นำด้านระบบน้ำคุณภาพสูง ราคาโรงงาน ท่อ PPR ท่อ HDPE อุปกรณ์วาล์ว ปั๊มน้ำ เครื่องเชื่อมท่อ และอุปกรณ์โรงงานคุณภาพ">
|
||||
@@ -330,49 +327,43 @@ Astro.cache.set(cacheHint);
|
||||
</div>
|
||||
|
||||
<div class="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
|
||||
{
|
||||
articles.length > 0 ? articles.map(article => (
|
||||
<a href={`/${encodeURI('บทความ')}/${encodeURIComponent(article.data.slug || article.id)}`} class="group block bg-white rounded-3xl overflow-hidden border border-slate-100 hover:border-primary-200 hover:shadow-xl transition-all duration-300">
|
||||
<div class="aspect-[16/9] bg-slate-100 overflow-hidden">
|
||||
{
|
||||
(() => {
|
||||
const img = article.data.featured_image;
|
||||
const imgSrc = typeof img === 'string' ? img : img?.src || (img?.provider === 'local' && (img?.meta?.storageKey || img?.id) ? `/_emdash/api/media/file/${img.meta?.storageKey || img.id}` : null);
|
||||
const imgAlt = typeof img === 'object' && img?.alt ? img.alt : article.data.title;
|
||||
return imgSrc ? (
|
||||
<img src={imgSrc} alt={imgAlt} class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500" loading="lazy" />
|
||||
) : (
|
||||
<div class="w-full h-full flex items-center justify-center text-slate-300">
|
||||
<svg class="w-16 h-16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
})()
|
||||
}
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<div class="flex items-center gap-3 text-sm text-slate-500 mb-3">
|
||||
<time datetime={article.data.publishedAt}>{new Date(article.data.publishedAt).toLocaleDateString('th-TH', { year: 'numeric', month: 'long', day: 'numeric' })}</time>
|
||||
{article.data.tags && (
|
||||
<span class="px-2.5 py-0.5 bg-primary-50 text-primary-600 rounded-full text-xs font-medium">{article.data.tags}</span>
|
||||
)}
|
||||
{articles.length > 0 && articles.map(article => (
|
||||
<a href={`/${encodeURI('บทความ')}/${encodeURIComponent(article.id)}`} class="group block bg-white rounded-3xl overflow-hidden border border-slate-100 hover:border-primary-200 hover:shadow-xl transition-all duration-300">
|
||||
<div class="aspect-[16/9] bg-slate-100 overflow-hidden">
|
||||
{article.data.featured_image ? (
|
||||
<img src={article.data.featured_image} alt={article.data.title} class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500" loading="lazy" />
|
||||
) : (
|
||||
<div class="w-full h-full flex items-center justify-center text-slate-300">
|
||||
<svg class="w-16 h-16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<h3 class="text-lg font-bold text-slate-900 group-hover:text-primary-600 transition-colors mb-2 line-clamp-2">{article.data.title}</h3>
|
||||
<p class="text-sm text-slate-600 line-clamp-2">{article.data.excerpt}</p>
|
||||
</div>
|
||||
</a>
|
||||
)) : (
|
||||
<div class="md:col-span-2 lg:col-span-3 text-center py-16">
|
||||
<div class="text-slate-300 mb-4">
|
||||
<svg class="w-16 h-16 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<p class="text-lg text-slate-400">ยังไม่มีบทความในขณะนี้</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
<div class="p-6">
|
||||
<div class="flex items-center gap-3 text-sm text-slate-500 mb-3">
|
||||
<time datetime={article.data.published_at.toISOString().slice(0, 10)}>
|
||||
{article.data.published_at.toLocaleDateString('th-TH', { year: 'numeric', month: 'long', day: 'numeric' })}
|
||||
</time>
|
||||
{article.data.tags?.[0] && (
|
||||
<span class="px-2.5 py-0.5 bg-primary-50 text-primary-600 rounded-full text-xs font-medium">{article.data.tags[0]}</span>
|
||||
)}
|
||||
</div>
|
||||
<h3 class="text-lg font-bold text-slate-900 group-hover:text-primary-600 transition-colors mb-2 line-clamp-2">{article.data.title}</h3>
|
||||
<p class="text-sm text-slate-600 line-clamp-2">{article.data.excerpt}</p>
|
||||
</div>
|
||||
</a>
|
||||
))}
|
||||
{articles.length === 0 && (
|
||||
<div class="md:col-span-2 lg:col-span-3 text-center py-16">
|
||||
<div class="text-slate-300 mb-4">
|
||||
<svg class="w-16 h-16 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<p class="text-lg text-slate-400">ยังไม่มีบทความในขณะนี้</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div class="text-center mt-10 sm:hidden">
|
||||
|
||||
Reference in New Issue
Block a user