feat: move articles link from 'blog/' to 'post/' paths

This commit is contained in:
grassblock 2025-05-04 11:42:09 +08:00
parent 350f6f3865
commit 7e5f8ce06f
9 changed files with 15 additions and 9 deletions

View file

@ -1,11 +1,17 @@
import { defineCollection } from 'astro:content'; import { defineCollection } from 'astro:content';
import { blogs } from './blog/_schemas'; import { posts } from './posts/_schemas';
import { pages } from "./pages/_schemas";
const blogCollection = defineCollection({ const blogCollection = defineCollection({
type: 'content', type: 'content',
schema: blogs, schema: posts,
});
const pageCollection = defineCollection({
type: 'content',
schema: pages,
}); });
export const collections = { export const collections = {
'blog': blogCollection, 'posts': blogCollection,
'pages': pageCollection,
}; };

View file

@ -1,6 +1,6 @@
import { z } from 'astro:content'; import { z } from 'astro:content';
export const blogs = z.object({ export const posts = z.object({
title: z.string(), title: z.string(),
description: z.string(), description: z.string(),
pubDate: z.coerce.date(), pubDate: z.coerce.date(),

View file

@ -2,7 +2,7 @@
import Layout from '../layouts/Layout.astro'; import Layout from '../layouts/Layout.astro';
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
const posts = await getCollection('blog'); const posts = await getCollection('posts');
posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime()); posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime());
--- ---
@ -18,7 +18,7 @@ posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDat
{posts.map((post) => ( {posts.map((post) => (
<p> <p>
<span style="color: var(--terminal-yellow);">{new Date(post.data.pubDate).toISOString().split('T')[0]}</span> <span style="color: var(--terminal-yellow);">{new Date(post.data.pubDate).toISOString().split('T')[0]}</span>
<a href={`/blog/${post.slug}`}>{post.data.title}</a> <a href={`/post/${post.slug}`}>{post.data.title}</a>
</p> </p>
))} ))}

View file

@ -3,7 +3,7 @@ import Layout from '../../layouts/Layout.astro';
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
export async function getStaticPaths() { export async function getStaticPaths() {
const blogEntries = await getCollection('blog'); const blogEntries = await getCollection('posts');
return blogEntries.map(entry => ({ return blogEntries.map(entry => ({
params: { slug: entry.slug }, props: { entry }, params: { slug: entry.slug }, props: { entry },
})); }));

View file

@ -21,7 +21,7 @@ export async function GET(context) {
const container = await AstroContainer.create({ renderers }); const container = await AstroContainer.create({ renderers });
// Load the content collection entries to add to our RSS feed. // Load the content collection entries to add to our RSS feed.
const posts = (await getCollection("blog")).sort((a, b) => const posts = (await getCollection("posts")).sort((a, b) =>
// Sort by publication date descending. // Sort by publication date descending.
a.data.pubDate > b.data.pubDate ? -1 : 1 a.data.pubDate > b.data.pubDate ? -1 : 1
); );

View file

@ -1,7 +1,7 @@
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
export async function GET() { export async function GET() {
const posts = await getCollection('blog'); const posts = await getCollection('posts');
const searchIndex = posts.map(post => ({ const searchIndex = posts.map(post => ({
title: post.data.title, title: post.data.title,
description: post.data.description, description: post.data.description,