feat: 前端添加robots.ts和sitemap.ts
All checks were successful
Deploy to K3s / deploy (push) Successful in 4m17s
All checks were successful
Deploy to K3s / deploy (push) Successful in 4m17s
This commit is contained in:
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]
|
||||
}
|
||||
Reference in New Issue
Block a user