Skip to content

Commit

Permalink
feat: basic sitemap generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Sep 9, 2024
1 parent 5af84fe commit 3c1d24f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { MetadataRoute } from "next";
import { client } from "../../studio/lib/client";
import { Slug } from "../../studio/lib/payloads/global";

interface SitemapDocument {
slug: Slug;
_updatedAt: string;
}

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const documents = await client.fetch<SitemapDocument[]>(`*[defined(slug)]`);

return documents.map((s) => ({
url: new URL(s.slug.current, process.env.NEXT_PUBLIC_URL).toString(),
lastModified: new Date(s._updatedAt),
}));
}

0 comments on commit 3c1d24f

Please sign in to comment.