Skip to content

Commit

Permalink
优化站点地图
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghao1993 committed Sep 11, 2024
1 parent 1cd06e3 commit ccfbf18
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { MetadataRoute } from "next";
import { getAllPostsMeta } from "../data/utils/index";
import {
getAllPostsMeta,
getAllTags,
getAllCategory,
} from "../data/utils/index";

export default function sitemap(): MetadataRoute.Sitemap {
const siteUrl = "https://super-super.cn/";
const allBlogs = getAllPostsMeta();
const allTags = getAllTags();
const categories = getAllCategory();
const blogRoutes = allBlogs.map((post) => ({
url: `${siteUrl}blog/${post.key}`,
lastModified: new Date().toISOString().split("T")[0],
Expand All @@ -14,5 +20,15 @@ export default function sitemap(): MetadataRoute.Sitemap {
lastModified: new Date().toISOString().split("T")[0],
}));

return [...routes, ...blogRoutes];
const tags = Object.keys(allTags).map((tag) => ({
url: `${siteUrl}blog/tag/${tag}`,
lastModified: new Date().toISOString().split("T")[0],
}));

const cats = Object.keys(categories).map((cat) => ({
url: `${siteUrl}blog/category/${cat}`,
lastModified: new Date().toISOString().split("T")[0],
}));

return [...routes, ...blogRoutes, ...tags, ...cats];
}
2 changes: 1 addition & 1 deletion components/Article/ArticleItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function ArticleItem(data: { articleInfo: Post }) {
data.articleInfo.categories.split(",").map((item) => (
<Link
key={item}
href={`blog/category/${item}`}
href={`/blog/category/${item}`}
className="px-2 mr-1 rounded-lg bg-primary-500 text-white min-w-10"
>
{item}
Expand Down

0 comments on commit ccfbf18

Please sign in to comment.