UNPKG

create-next-pro-cli

Version:

Advanced Next.js project scaffolder with i18n, Tailwind, App Router and more.

28 lines (23 loc) 762 B
import { MetadataRoute } from "next"; import { Locale } from "next-intl"; import { host } from "@/config"; import { routing } from "@/lib/i18n/routing"; import { getPathname } from "@/lib/i18n/navigation"; export default function sitemap(): MetadataRoute.Sitemap { return [...getEntries("/"), ...getEntries("/pathnames")]; } type Href = Parameters<typeof getPathname>[0]["href"]; function getEntries(href: Href) { return routing.locales.map((locale) => ({ url: getUrl(href, locale), alternates: { languages: Object.fromEntries( routing.locales.map((cur) => [cur, getUrl(href, cur)]) ), }, })); } function getUrl(href: Href, locale: Locale) { const pathname = getPathname({ locale, href }); return host + pathname; }