Compare commits

6 Commits

Author SHA1 Message Date
616b1ad389 feat: 前端添加robots.ts和sitemap.ts
All checks were successful
Deploy to K3s / deploy (push) Successful in 4m17s
2025-12-24 14:03:34 +08:00
0ef987932f chore: 前端调整博客结构定义 2025-12-24 14:02:03 +08:00
004548c9df feat: 后端博客列表时,添加updatedAt字段 2025-12-24 13:59:30 +08:00
941633bdb4 chore: 移除next-sitemap... 2025-12-24 13:58:58 +08:00
abaa16a0f9 feat: 博客在站内打开 2025-12-24 13:42:56 +08:00
f64b9bb469 chore: 前端添加next-sitemap依赖 2025-12-24 13:42:29 +08:00
7 changed files with 65 additions and 4 deletions

View File

@@ -35,9 +35,10 @@ export class BlogService {
return i;
}
const { createdAt, deletedAt, id, title, viewCount, description } = i;
const { createdAt, updatedAt, deletedAt, id, title, viewCount, description } = i;
return {
createdAt,
updatedAt,
deletedAt,
id,
title,

View File

@@ -57,7 +57,6 @@ export default async function Blog() {
<a
className="hover:underline focus:outline-none focus:ring-2 focus:ring-zinc-400 rounded"
href={getBlogDetailUrl(blog.id)}
target="_blank"
rel="noopener noreferrer"
>
{blog.title}

View File

@@ -0,0 +1,12 @@
import { MetadataRoute } from 'next'
export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: '*',
allow: '/',
disallow: '/console',
},
sitemap: 'https://www.tonesc.cn/sitemap.xml',
}
}

View File

@@ -0,0 +1,45 @@
import { BlogAPI } from '@/lib/api/server'
import { base62 } from '@/lib/utils'
import { MetadataRoute } from 'next'
export const revalidate = 3600;
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
// 获取所有博客
const blogs = await BlogAPI.list().catch(() => [])
const blogUrls = blogs.map(blog => {
const cleanId = blog.id.replace(/-/g, '')
const encoded = base62.encode(Buffer.from(cleanId, 'hex'))
return {
url: `https://www.tonesc.cn/blog/${encoded}`,
lastModified: new Date(blog.updatedAt),
changeFrequency: 'weekly' as const,
priority: 0.8,
}
})
// 静态页面
const staticUrls = [
{
url: 'https://www.tonesc.cn/',
lastModified: new Date(),
changeFrequency: 'yearly' as const,
priority: 1,
},
{
url: 'https://www.tonesc.cn/blog',
lastModified: new Date(),
changeFrequency: 'daily' as const,
priority: 0.9,
},
{
url: 'https://www.tonesc.cn/resource',
lastModified: new Date(),
changeFrequency: 'monthly' as const,
priority: 0.7,
},
]
return [...staticUrls, ...blogUrls]
}

View File

@@ -2,5 +2,7 @@ import { Blog } from "@/lib/types/blog";
import { serverFetch } from "../server";
export async function list() {
return serverFetch<Blog[]>('/api/blog')
return serverFetch<Pick<Blog,
'id' | 'title' | 'description' | 'viewCount' | 'createdAt' | 'updatedAt' | 'deletedAt'
>[]>('/api/blog')
}

View File

@@ -7,5 +7,7 @@ export interface Blog {
viewCount: number;
contentUrl: string;
createdAt: string;
updatedAt: string;
deletedAt: string;
permissions: BlogPermission[];
}