From 6cfb56d4bc0b21d9770c28b4e82c65209cc296b9 Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Wed, 2 Oct 2024 17:00:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8D=EF=B8=8F=20Add=20sitemap=20(#1371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/landing/src/app/sitemap.ts | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 apps/landing/src/app/sitemap.ts diff --git a/apps/landing/src/app/sitemap.ts b/apps/landing/src/app/sitemap.ts new file mode 100644 index 000000000..b5155e181 --- /dev/null +++ b/apps/landing/src/app/sitemap.ts @@ -0,0 +1,54 @@ +import { supportedLngs } from "@rallly/languages"; +import type { MetadataRoute } from "next"; + +import { getAllPosts } from "@/lib/api"; +import { absoluteUrl } from "@/utils/absolute-url"; + +const alternateLanguages = supportedLngs.filter((lng) => lng !== "en"); + +const getAlternateLanguages = (path: string) => { + return alternateLanguages.reduce>((acc, locale) => { + acc[locale] = absoluteUrl(`/${locale}${path}`); + return acc; + }, {}); +}; + +export default async function Sitemap(): Promise { + const posts = getAllPosts(["slug"]); + + return [ + { + url: absoluteUrl(), + lastModified: new Date(), + changeFrequency: "weekly", + priority: 1, + alternates: { + languages: getAlternateLanguages("/"), + }, + }, + { + url: absoluteUrl("/pricing"), + lastModified: new Date(), + changeFrequency: "weekly", + priority: 0.8, + alternates: { + languages: getAlternateLanguages("/pricing"), + }, + }, + { + url: absoluteUrl("/blog"), + lastModified: new Date(), + changeFrequency: "weekly", + priority: 0.8, + alternates: { + languages: getAlternateLanguages("/blog"), + }, + }, + ...posts.map((post) => ({ + url: absoluteUrl(`/blog/${post.slug}`), + lastModified: new Date(), // TODO: Update posts to include a lastModified date + changeFrequency: "yearly" as const, + priority: 0.7, + })), + ]; +}