Skip to content

Commit 73a1862

Browse files
committed
feat: sitemap&robots
1 parent 1521963 commit 73a1862

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const metadata: Metadata = {
2929
'max-image-preview': 'large',
3030
'max-snippet': -1,
3131
},
32-
}, //爬虫
32+
},
3333
openGraph: {
3434
title: {
3535
default: seo.title,

src/app/robots.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { MetadataRoute } from 'next';
2+
3+
import { siteUrl } from '~/seo';
4+
5+
export default function robots(): MetadataRoute.Robots {
6+
return {
7+
rules: [
8+
{
9+
userAgent: '*',
10+
allow: '/',
11+
disallow: ['/og'],
12+
},
13+
],
14+
sitemap: `${siteUrl}/sitemap.xml`,
15+
};
16+
}

src/app/sitemap.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { MetadataRoute } from 'next';
2+
3+
import { siteUrl } from '~/seo';
4+
import { buildPostData } from '@/core';
5+
6+
const { postDataList } = buildPostData();
7+
8+
export default function sitemap(): MetadataRoute.Sitemap {
9+
const postSitemap = postDataList.map((post) => ({
10+
url: `${siteUrl}/notes/${post.title}`,
11+
lastModified: post.updatedAt!,
12+
}));
13+
14+
return [
15+
{ url: `${siteUrl}` },
16+
{ url: `${siteUrl}/list` },
17+
{ url: `${siteUrl}/friends` },
18+
{ url: `${siteUrl}/about` },
19+
{ url: `${siteUrl}/projects` },
20+
...postSitemap,
21+
];
22+
}

0 commit comments

Comments
 (0)