Align home and blog lists with reference style

This commit is contained in:
2025-11-17 17:53:06 +08:00
parent 2654e92147
commit 0bff9bf7f6
3 changed files with 90 additions and 15 deletions

View File

@@ -1,21 +1,23 @@
import { getAllPostsSorted } from '@/lib/posts'; import { getAllPostsSorted } from '@/lib/posts';
import { PostCard } from '@/components/post-card'; import { PostListItem } from '@/components/post-list-item';
export const metadata = { export const metadata = {
title: 'Blog' title: '所有文章'
}; };
export default function BlogIndexPage() { export default function BlogIndexPage() {
const posts = getAllPostsSorted(); const posts = getAllPostsSorted();
return ( return (
<section className="space-y-6"> <section className="space-y-4">
<h1 className="text-2xl font-bold">Blog</h1> <h1 className="text-lg font-semibold text-slate-900 dark:text-slate-50">
<div className="space-y-4">
</h1>
<ul className="space-y-3">
{posts.map((post) => ( {posts.map((post) => (
<PostCard key={post._id} post={post} /> <PostListItem key={post._id} post={post} />
))} ))}
</div> </ul>
</section> </section>
); );
} }

View File

@@ -1,31 +1,39 @@
import Link from 'next/link'; import Link from 'next/link';
import { getAllPostsSorted } from '@/lib/posts'; import { getAllPostsSorted } from '@/lib/posts';
import { siteConfig } from '@/lib/config'; import { siteConfig } from '@/lib/config';
import { Hero } from '@/components/hero'; import { PostListItem } from '@/components/post-list-item';
import { PostCard } from '@/components/post-card';
export default function HomePage() { export default function HomePage() {
const posts = getAllPostsSorted().slice(0, siteConfig.postsPerPage); const posts = getAllPostsSorted().slice(0, siteConfig.postsPerPage);
return ( return (
<section className="space-y-6"> <section className="space-y-6">
<Hero /> <header className="space-y-1">
<h1 className="text-lg font-semibold text-slate-900 dark:text-slate-50">
{siteConfig.name}
</h1>
<p className="text-sm text-slate-600 dark:text-slate-300">
{siteConfig.tagline}
</p>
</header>
<div> <div>
<div className="mb-3 flex items-baseline justify-between"> <div className="mb-3 flex items-baseline justify-between">
<h2 className="text-xl font-semibold"></h2> <h2 className="text-sm font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400">
</h2>
<Link <Link
href="/blog" href="/blog"
className="text-sm text-blue-600 hover:underline dark:text-blue-400" className="text-xs text-blue-600 hover:underline dark:text-blue-400"
> >
</Link> </Link>
</div> </div>
<div className="space-y-4"> <ul className="space-y-3">
{posts.map((post) => ( {posts.map((post) => (
<PostCard key={post._id} post={post} /> <PostListItem key={post._id} post={post} />
))} ))}
</div> </ul>
</div> </div>
</section> </section>
); );

View File

@@ -0,0 +1,65 @@
import Link from 'next/link';
import type { Post } from 'contentlayer/generated';
import { siteConfig } from '@/lib/config';
interface Props {
post: Post;
}
export function PostListItem({ post }: Props) {
const cover =
post.feature_image && post.feature_image.startsWith('../assets')
? post.feature_image.replace('../assets', '/assets')
: undefined;
return (
<li>
<Link href={post.url}>
<article className="group flex gap-4 rounded-lg border border-slate-200/70 bg-white/80 p-4 transition hover:bg-slate-50 dark:border-slate-800 dark:bg-slate-900/80 dark:hover:bg-slate-900">
{cover && (
<div className="hidden flex-none overflow-hidden rounded-md bg-slate-100 dark:bg-slate-800 sm:block sm:w-40">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={cover}
alt={post.title}
className="h-full w-full object-contain"
/>
</div>
)}
<div className="flex-1 space-y-1">
<div className="flex flex-wrap items-center gap-2 text-xs text-slate-500 dark:text-slate-400">
{post.published_at && (
<time>
{new Date(post.published_at).toLocaleDateString(
siteConfig.defaultLocale
)}
</time>
)}
{post.tags && post.tags.length > 0 && (
<span className="flex flex-wrap gap-1">
{post.tags.slice(0, 3).map((t) => (
<span
key={t}
className="rounded bg-slate-100 px-1.5 py-0.5 text-[11px] text-slate-600 group-hover:bg-slate-200 dark:bg-slate-800 dark:text-slate-200 dark:group-hover:bg-slate-700"
>
#{t}
</span>
))}
</span>
)}
</div>
<h2 className="text-base font-semibold text-slate-900 group-hover:text-blue-600 dark:text-slate-50 dark:group-hover:text-blue-400">
{post.title}
</h2>
{post.description && (
<p className="line-clamp-2 text-sm text-slate-600 group-hover:text-slate-800 dark:text-slate-200 dark:group-hover:text-slate-100">
{post.description}
</p>
)}
</div>
</article>
</Link>
</li>
);
}