Compare commits
6 Commits
f2afe4f7ee
...
616b1ad389
| Author | SHA1 | Date | |
|---|---|---|---|
| 616b1ad389 | |||
| 0ef987932f | |||
| 004548c9df | |||
| 941633bdb4 | |||
| abaa16a0f9 | |||
| f64b9bb469 |
@@ -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,
|
||||
|
||||
@@ -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}
|
||||
|
||||
12
apps/frontend/app/robots.ts
Normal file
12
apps/frontend/app/robots.ts
Normal 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',
|
||||
}
|
||||
}
|
||||
45
apps/frontend/app/sitemap.ts
Normal file
45
apps/frontend/app/sitemap.ts
Normal 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]
|
||||
}
|
||||
@@ -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')
|
||||
}
|
||||
@@ -7,5 +7,7 @@ export interface Blog {
|
||||
viewCount: number;
|
||||
contentUrl: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
deletedAt: string;
|
||||
permissions: BlogPermission[];
|
||||
}
|
||||
@@ -74,4 +74,4 @@
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user