♻️ 使用 NextJS 重构 #1
@@ -16,14 +16,6 @@ export async function GET() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  const posts = await client.fetch<any[]>(`*[_type == "post"] {
 | 
					  const posts = await client.fetch<any[]>(`*[_type == "post"] {
 | 
				
			||||||
    title, description, slug, publishedAt,
 | 
					    title, description, slug, publishedAt,
 | 
				
			||||||
    mainImage {
 | 
					 | 
				
			||||||
      asset -> {
 | 
					 | 
				
			||||||
        _id,
 | 
					 | 
				
			||||||
        url
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      alt
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    "categories": categories[]->title,
 | 
					 | 
				
			||||||
  }`);
 | 
					  }`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  posts.forEach((item) => {
 | 
					  posts.forEach((item) => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,11 @@
 | 
				
			|||||||
import { MetadataRoute } from "next";
 | 
					import { MetadataRoute } from "next";
 | 
				
			||||||
import { getSortedPosts, Post } from "@/content/posts";
 | 
					 | 
				
			||||||
import { SITE_URL } from "@/app/consts";
 | 
					import { SITE_URL } from "@/app/consts";
 | 
				
			||||||
 | 
					import { client } from "@/sanity/lib/client";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function sitemap(): MetadataRoute.Sitemap {
 | 
					export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
 | 
				
			||||||
  const posts = getSortedPosts();
 | 
					  const posts = await client.fetch<any[]>(`*[_type == "post"] {
 | 
				
			||||||
 | 
					    slug, publishedAt,
 | 
				
			||||||
 | 
					  }`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return [
 | 
					  return [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -19,9 +21,9 @@ export default function sitemap(): MetadataRoute.Sitemap {
 | 
				
			|||||||
      priority: 0.8,
 | 
					      priority: 0.8,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ...posts.map((item: Post) => ({
 | 
					    ...posts.map((item: any) => ({
 | 
				
			||||||
      url: `${SITE_URL}/posts/${item.id}`,
 | 
					      url: `${SITE_URL}/posts/${item.slug.current}`,
 | 
				
			||||||
      lastModified: item.date,
 | 
					      lastModified: new Date(item.publishedAt),
 | 
				
			||||||
      changeFrequency: "daily" as any,
 | 
					      changeFrequency: "daily" as any,
 | 
				
			||||||
      priority: 0.75,
 | 
					      priority: 0.75,
 | 
				
			||||||
    })),
 | 
					    })),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user