11import { availableLocaleCodes , defaultLocale } from '@node-core/website-i18n' ;
22
3- import { BASE_PATH } from '#site/next.constants.mjs' ;
4- import { BASE_URL } from '#site/next.constants.mjs' ;
5- import { EXTERNAL_LINKS_SITEMAP } from '#site/next.constants.mjs' ;
3+ import {
4+ BASE_PATH ,
5+ BASE_URL ,
6+ EXTERNAL_LINKS_SITEMAP ,
7+ } from '#site/next.constants.mjs' ;
68import { BLOG_DYNAMIC_ROUTES } from '#site/next.dynamic.constants.mjs' ;
79import { dynamicRouter } from '#site/next.dynamic.mjs' ;
810
@@ -16,8 +18,11 @@ const nonDefaultLocales = availableLocaleCodes.filter(
1618 l => l !== defaultLocale . code
1719) ;
1820
19- const getAlternatePath = ( r : string , locales : Array < string > ) =>
20- Object . fromEntries ( locales . map ( l => [ l , `${ baseUrlAndPath } /${ l } /${ r } ` ] ) ) ;
21+ const getFullPath = ( r : string , l : string ) =>
22+ / ^ h t t p s ? : \/ \/ / . test ( r ) ? r : `${ baseUrlAndPath } /${ l } /${ r } ` ;
23+
24+ const getAlternatePaths = ( r : string , locales : Array < string > ) =>
25+ Object . fromEntries ( locales . map ( l => [ l , getFullPath ( r , l ) ] ) ) ;
2126
2227// This allows us to generate a `sitemap.xml` file dynamically based on the needs of the Node.js Website
2328const sitemap = async ( ) : Promise < MetadataRoute . Sitemap > => {
@@ -27,10 +32,10 @@ const sitemap = async (): Promise<MetadataRoute.Sitemap> => {
2732 const currentDate = new Date ( ) . toISOString ( ) ;
2833
2934 const getSitemapEntry = ( r : string , locales : Array < string > = [ ] ) => ( {
30- url : ` ${ baseUrlAndPath } / ${ defaultLocale . code } / ${ r } ` ,
35+ url : getFullPath ( r , defaultLocale . code ) ,
3136 lastModified : currentDate ,
3237 changeFrequency : 'always' as const ,
33- alternates : { languages : getAlternatePath ( r , locales ) } ,
38+ alternates : { languages : getAlternatePaths ( r , locales ) } ,
3439 } ) ;
3540
3641 const staticPaths = routes . map ( r => getSitemapEntry ( r , nonDefaultLocales ) ) ;
0 commit comments