2024-02-24 13:56:35 +00:00
|
|
|
import { Button, Card, CardActions, CardContent, CardMedia, Chip, Stack, Typography } from "@mui/material";
|
|
|
|
import { client } from "@/sanity/lib/client";
|
2024-02-24 09:33:35 +00:00
|
|
|
import Image from "next/image";
|
|
|
|
import Link from "next/link";
|
|
|
|
|
2024-02-24 17:36:12 +00:00
|
|
|
export const metadata = {
|
|
|
|
title: "博客"
|
|
|
|
}
|
|
|
|
|
2024-02-24 13:56:35 +00:00
|
|
|
export default async function PostList() {
|
|
|
|
const posts = await client.fetch<any[]>(`*[_type == "post"] {
|
|
|
|
title, description, slug, author, publishedAt,
|
|
|
|
mainImage {
|
|
|
|
asset -> {
|
|
|
|
_id,
|
|
|
|
url
|
|
|
|
},
|
|
|
|
alt
|
|
|
|
},
|
|
|
|
"categories": categories[]->title,
|
|
|
|
"author_name": author->name,
|
|
|
|
"author_image": author->image
|
|
|
|
}`);
|
2024-02-24 09:33:35 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
posts.map((post) => (
|
2024-02-24 13:56:35 +00:00
|
|
|
<Card key={post.slug.current} sx={{ width: "100%" }}>
|
2024-02-24 09:33:35 +00:00
|
|
|
{
|
2024-02-24 13:56:35 +00:00
|
|
|
post.mainImage &&
|
|
|
|
<CardMedia sx={{ height: 160, position: "relative" }} title={post.mainImage.alt}>
|
2024-02-24 09:33:35 +00:00
|
|
|
<Image
|
|
|
|
fill
|
2024-02-24 13:56:35 +00:00
|
|
|
src={post.mainImage.asset.url}
|
|
|
|
alt={post.mainImage.alt}
|
2024-02-24 09:33:35 +00:00
|
|
|
style={{ objectFit: "cover" }}
|
|
|
|
/>
|
|
|
|
</CardMedia>
|
|
|
|
}
|
|
|
|
|
|
|
|
<CardContent sx={{ paddingX: 5, paddingY: 3 }}>
|
2024-02-24 13:56:35 +00:00
|
|
|
<Typography variant="h3">
|
2024-02-24 09:33:35 +00:00
|
|
|
{post.title}
|
|
|
|
</Typography>
|
2024-02-24 13:56:35 +00:00
|
|
|
|
|
|
|
<Stack direction="row" sx={{ mx: -0.5, mt: 1, mb: 1.2 }}>
|
|
|
|
{post.categories.map((category: string, idx: number) => <Chip size="small" label={category} key={idx} />)}
|
|
|
|
</Stack>
|
2024-02-24 09:33:35 +00:00
|
|
|
<Typography variant="body2" color="text.secondary">
|
2024-02-24 13:56:35 +00:00
|
|
|
{post.description ? post.description : "No description yet."}
|
2024-02-24 09:33:35 +00:00
|
|
|
</Typography>
|
|
|
|
</CardContent>
|
|
|
|
<CardActions sx={{ paddingX: 4, paddingBottom: 2 }}>
|
2024-02-24 13:56:35 +00:00
|
|
|
<Link href={`/p/${post.slug.current}`} passHref>
|
2024-02-24 09:33:35 +00:00
|
|
|
<Button>Read more</Button>
|
|
|
|
</Link>
|
|
|
|
</CardActions>
|
|
|
|
</Card>
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|