feat: Upgrade to Astro 6
- Astro 5.x → Astro 6.1.2 - @astrojs/node 9.x → 10.x - Content config: src/content/config.ts → src/content.config.ts - Update to glob loader pattern for content collections - Replace post.slug with post.id for content loader - Replace post.render() with render(post)
This commit is contained in:
BIN
data/consent.db
BIN
data/consent.db
Binary file not shown.
1353
package-lock.json
generated
1353
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -16,11 +16,11 @@
|
|||||||
"db:seed": "astro db seed"
|
"db:seed": "astro db seed"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/db": "^0.20.0",
|
"@astrojs/db": "^0.20.1",
|
||||||
"@astrojs/node": "^9.5.4",
|
"@astrojs/node": "^10.0.4",
|
||||||
"@astrojs/sitemap": "^3.7.2",
|
"@astrojs/sitemap": "^3.7.2",
|
||||||
"@tailwindcss/vite": "^4.2.1",
|
"@tailwindcss/vite": "^4.2.1",
|
||||||
"astro": "^5.17.1",
|
"astro": "^6.1.2",
|
||||||
"astro-consent": "^1.0.17",
|
"astro-consent": "^1.0.17",
|
||||||
"better-sqlite3": "^12.8.0",
|
"better-sqlite3": "^12.8.0",
|
||||||
"drizzle-orm": "^0.45.1",
|
"drizzle-orm": "^0.45.1",
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { defineCollection, z } from 'astro:content';
|
import { defineCollection, z } from 'astro:content';
|
||||||
|
import { glob } from 'astro/loaders';
|
||||||
|
|
||||||
const blog = defineCollection({
|
const blog = defineCollection({
|
||||||
type: 'content',
|
loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
description: z.string(),
|
description: z.string(),
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
---
|
---
|
||||||
import Layout from '../../layouts/Layout.astro';
|
import Layout from '../../layouts/Layout.astro';
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection, render } from 'astro:content';
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const posts = await getCollection('blog');
|
const posts = await getCollection('blog');
|
||||||
return posts.map(post => ({
|
return posts.map(post => ({
|
||||||
params: { slug: post.slug },
|
params: { slug: post.id },
|
||||||
props: { post },
|
props: { post },
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const { post } = Astro.props;
|
const { post } = Astro.props;
|
||||||
const { Content } = await post.render();
|
const { Content } = await render(post);
|
||||||
|
|
||||||
// Map blog slugs to feature images
|
// Map blog slugs to feature images
|
||||||
const featureImages: Record<string, string> = {
|
const featureImages: Record<string, string> = {
|
||||||
@@ -27,7 +27,7 @@ const featureImages: Record<string, string> = {
|
|||||||
'website-2026-must-have': '/images/blog/website-2026.jpg',
|
'website-2026-must-have': '/images/blog/website-2026.jpg',
|
||||||
};
|
};
|
||||||
|
|
||||||
const featureImage = featureImages[post.slug] || '/images/blog/ai-sales-growth.jpg';
|
const featureImage = featureImages[post.id] || '/images/blog/ai-sales-growth.jpg';
|
||||||
|
|
||||||
const formatDate = (date: Date) => {
|
const formatDate = (date: Date) => {
|
||||||
return date.toLocaleDateString('th-TH', {
|
return date.toLocaleDateString('th-TH', {
|
||||||
@@ -60,7 +60,7 @@ const schemaData = {
|
|||||||
},
|
},
|
||||||
"mainEntityOfPage": {
|
"mainEntityOfPage": {
|
||||||
"@type": "WebPage",
|
"@type": "WebPage",
|
||||||
"@id": `https://www.moreminimore.com/blog/${post.slug}`
|
"@id": `https://www.moreminimore.com/blog/${post.id}`
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ const breadcrumbSchema = {
|
|||||||
"@type": "ListItem",
|
"@type": "ListItem",
|
||||||
"position": 3,
|
"position": 3,
|
||||||
"name": post.data.title,
|
"name": post.data.title,
|
||||||
"item": `https://www.moreminimore.com/blog/${post.slug}`
|
"item": `https://www.moreminimore.com/blog/${post.id}`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { getCollection } from 'astro:content';
|
|||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const posts = await getCollection('blog');
|
const posts = await getCollection('blog');
|
||||||
return posts.map(post => ({
|
return posts.map(post => ({
|
||||||
params: { slug: post.slug },
|
params: { slug: post.id },
|
||||||
props: { post },
|
props: { post },
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ const formatDate = (date: Date) => {
|
|||||||
<!-- Feature Image -->
|
<!-- Feature Image -->
|
||||||
<div class="relative h-48 overflow-hidden">
|
<div class="relative h-48 overflow-hidden">
|
||||||
<img
|
<img
|
||||||
src={featureImages[post.slug] || '/images/blog/ai-sales-growth.jpg'}
|
src={featureImages[post.id] || '/images/blog/ai-sales-growth.jpg'}
|
||||||
alt={post.data.title}
|
alt={post.data.title}
|
||||||
class="w-full h-full object-cover transform group-hover:scale-110 transition-transform duration-500"
|
class="w-full h-full object-cover transform group-hover:scale-110 transition-transform duration-500"
|
||||||
/>
|
/>
|
||||||
@@ -147,7 +147,7 @@ const formatDate = (date: Date) => {
|
|||||||
<span class="text-sm text-gray-600">{formatDate(post.data.pubDate)}</span>
|
<span class="text-sm text-gray-600">{formatDate(post.data.pubDate)}</span>
|
||||||
</div>
|
</div>
|
||||||
<h2 class="text-xl font-bold mb-3 line-clamp-2 group-hover:text-yellow-600 transition-colors">
|
<h2 class="text-xl font-bold mb-3 line-clamp-2 group-hover:text-yellow-600 transition-colors">
|
||||||
<a href={`/blog/${post.slug}`}>{post.data.title}</a>
|
<a href={`/blog/${post.id}`}>{post.data.title}</a>
|
||||||
</h2>
|
</h2>
|
||||||
<p class="text-gray-700 mb-4 line-clamp-2">
|
<p class="text-gray-700 mb-4 line-clamp-2">
|
||||||
{post.data.description}
|
{post.data.description}
|
||||||
@@ -157,7 +157,7 @@ const formatDate = (date: Date) => {
|
|||||||
<span class="text-xs bg-gray-100 px-2 py-1 rounded text-gray-700">#{tag}</span>
|
<span class="text-xs bg-gray-100 px-2 py-1 rounded text-gray-700">#{tag}</span>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<a href={`/blog/${post.slug}`} class="text-yellow-600 font-medium hover:text-yellow-800 inline-flex items-center gap-2 group-hover:gap-3 transition-all">
|
<a href={`/blog/${post.id}`} class="text-yellow-600 font-medium hover:text-yellow-800 inline-flex items-center gap-2 group-hover:gap-3 transition-all">
|
||||||
อ่านเพิ่มเติม →
|
อ่านเพิ่มเติม →
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user