fix: 修复后台文章计数为0 + 分类编辑补全描述字段 + CSP放行外部图片 + 更新关于页描述
- 文章管理:计数请求补 page=1 参数,命中分页接口返回正确的 total - 分类管理:编辑模式新增描述输入框,保存时一并提交 description - CSP:img-src 加入 https: 允许加载外部图片 - 关于页:数据存储描述从 JSON 文件更正为 SQLite 数据库 - Footer:添加 ICP 备案号
This commit is contained in:
@@ -1,29 +1,76 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { posts } from "@/data/posts";
|
||||
import { getPostBySlug, getPublishedPosts } from "@/lib/store";
|
||||
import PostContent from "@/components/PostContent";
|
||||
|
||||
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://asui.xyz";
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const posts = await getPublishedPosts();
|
||||
return posts.map((post) => ({ slug: post.slug }));
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }) {
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ slug: string }>;
|
||||
}): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const post = posts.find((p) => p.slug === slug);
|
||||
const post = await getPostBySlug(slug);
|
||||
if (!post) return {};
|
||||
|
||||
const url = `${SITE_URL}/posts/${post.slug}`;
|
||||
return {
|
||||
title: post.title,
|
||||
description: post.excerpt,
|
||||
alternates: { canonical: url },
|
||||
openGraph: {
|
||||
title: post.title,
|
||||
description: post.excerpt,
|
||||
url,
|
||||
type: "article",
|
||||
publishedTime: post.date,
|
||||
authors: ["胡旭"],
|
||||
tags: post.tags,
|
||||
siteName: "随 · asui.xyz",
|
||||
locale: "zh_CN",
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: post.title,
|
||||
description: post.excerpt,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default async function PostPage({ params }: { params: Promise<{ slug: string }> }) {
|
||||
const { slug } = await params;
|
||||
const post = posts.find((p) => p.slug === slug);
|
||||
const post = await getPostBySlug(slug);
|
||||
if (!post) notFound();
|
||||
|
||||
const currentIndex = posts.findIndex((p) => p.slug === slug);
|
||||
const prevPost = currentIndex > 0 ? posts[currentIndex - 1] : null;
|
||||
const nextPost = currentIndex < posts.length - 1 ? posts[currentIndex + 1] : null;
|
||||
const all = await getPublishedPosts();
|
||||
const currentIndex = all.findIndex((p) => p.slug === slug);
|
||||
const prevPost = currentIndex > 0 ? all[currentIndex - 1] : null;
|
||||
const nextPost = currentIndex < all.length - 1 ? all[currentIndex + 1] : null;
|
||||
|
||||
return <PostContent post={post} prevPost={prevPost} nextPost={nextPost} />;
|
||||
// BlogPosting 结构化数据,利于搜索引擎富摘要
|
||||
const jsonLd = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BlogPosting",
|
||||
headline: post.title,
|
||||
description: post.excerpt,
|
||||
datePublished: post.date,
|
||||
dateModified: post.updatedAt,
|
||||
author: { "@type": "Person", name: "胡旭", url: SITE_URL },
|
||||
publisher: { "@type": "Person", name: "胡旭" },
|
||||
mainEntityOfPage: `${SITE_URL}/posts/${post.slug}`,
|
||||
keywords: post.tags.join(", "),
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />
|
||||
<PostContent post={post} prevPost={prevPost} nextPost={nextPost} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user