better-auth/apps/web/app/sitemap.ts
 Илья Шалонин 8538ab969a first
2025-10-29 13:43:43 +05:00

43 lines
1.3 KiB
TypeScript

import { getAllPosts } from "@marketing/blog/utils/lib/posts";
import { config } from "@repo/config";
import { getBaseUrl } from "@repo/utils";
import { allLegalPages } from "content-collections";
import type { MetadataRoute } from "next";
import { docsSource } from "./docs-source";
const baseUrl = getBaseUrl();
const locales = config.i18n.enabled
? Object.keys(config.i18n.locales)
: [config.i18n.defaultLocale];
const staticMarketingPages = ["", "/changelog"];
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const posts = await getAllPosts();
return [
...staticMarketingPages.flatMap((page) =>
locales.map((locale) => ({
url: new URL(`/${locale}${page}`, baseUrl).href,
lastModified: new Date(),
})),
),
...posts.map((post) => ({
url: new URL(`/${post.locale}/blog/${post.path}`, baseUrl).href,
lastModified: new Date(),
})),
...allLegalPages.map((page) => ({
url: new URL(`/${page.locale}/legal/${page.path}`, baseUrl).href,
lastModified: new Date(),
})),
...docsSource.getLanguages().flatMap((locale) =>
docsSource.getPages(locale.language).map((page) => ({
url: new URL(
`/${locale.language}/docs/${page.slugs.join("/")}`,
baseUrl,
).href,
lastModified: new Date(),
})),
),
];
}