prmbr-image-mksaas/src/sitemap.ts
javayhu df1c75f56a chore: upgrade next-intl to version 4.0.0 and update type definitions
- Update `next-intl` dependency from version 3.26.5 to 4.0.0
- Modify global type definitions to include new `Locale` and `Messages` types
- Refactor various components and pages to use `Locale` type for params
- Enhance internationalization handling by integrating `hasLocale` checks
- Clean up imports and ensure consistent usage of `next-intl` features
2025-03-13 00:23:37 +08:00

35 lines
1.0 KiB
TypeScript

import { MetadataRoute } from 'next';
import { routing } from '@/i18n/routing';
import { getLocalePathname } from '@/i18n/navigation';
import { getBaseUrl } from './lib/urls/get-base-url';
import { Locale } from 'next-intl';
/**
* https://github.com/javayhu/cnblocks/blob/main/app/sitemap.ts
*/
export default function sitemap(): MetadataRoute.Sitemap {
return [...getEntries('/')];
}
type Href = Parameters<typeof getLocalePathname>[0]['href'];
/**
* https://next-intl.dev/docs/environments/actions-metadata-route-handlers#sitemap
* https://github.com/amannn/next-intl/blob/main/examples/example-app-router/src/app/sitemap.ts
*/
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 = getLocalePathname({ locale, href });
return getBaseUrl() + pathname;
}