@@ -11,38 +11,23 @@ import { getAllPages } from '@/lib/repositories/pageRepository';
1111import { getAllPublishedPageFolders } from '@/lib/repositories/pageFolderRepository' ;
1212import { getAllLocales } from '@/lib/repositories/localeRepository' ;
1313import { getTranslationsByLocale } from '@/lib/repositories/translationRepository' ;
14- import { getSettingByKey } from '@/lib/repositories/settingsRepository' ;
14+ import { getSettingsByKeys } from '@/lib/repositories/settingsRepository' ;
1515import { getItemsByCollectionId } from '@/lib/repositories/collectionItemRepository' ;
1616import { getValuesByItemIds } from '@/lib/repositories/collectionItemValueRepository' ;
1717import {
1818 generateSitemapUrls ,
1919 generateSitemapXml ,
2020 getDefaultSitemapSettings ,
2121} from '@/lib/sitemap-utils' ;
22+ import { getSiteBaseUrl } from '@/lib/url-utils' ;
2223import type { SitemapSettings , Translation , CollectionItem } from '@/types' ;
2324
24- /**
25- * Get the base URL for sitemap generation
26- */
27- function getBaseUrl ( ) : string {
28- // Use environment variable if set
29- if ( process . env . NEXT_PUBLIC_SITE_URL ) {
30- return process . env . NEXT_PUBLIC_SITE_URL . replace ( / \/ $ / , '' ) ;
31- }
32-
33- // Fallback to Vercel URL
34- if ( process . env . VERCEL_URL ) {
35- return `https://${ process . env . VERCEL_URL } ` ;
36- }
37-
38- return '' ;
39- }
40-
4125export async function GET ( ) {
4226 try {
4327 const hasSupabaseCredentials = await credentials . exists ( ) ;
4428 if ( ! hasSupabaseCredentials ) {
4529 const xml = generateSitemapXml ( [ ] ) ;
30+
4631 return new NextResponse ( xml , {
4732 headers : {
4833 'Content-Type' : 'application/xml' ,
@@ -51,9 +36,9 @@ export async function GET() {
5136 } ) ;
5237 }
5338
54- // Get sitemap settings
55- const storedSettings = await getSettingByKey ( 'sitemap' ) ;
56- const settings : SitemapSettings = storedSettings || getDefaultSitemapSettings ( ) ;
39+ const allSettings = await getSettingsByKeys ( [ ' sitemap' , 'global_canonical_url' ] ) ;
40+ const settings : SitemapSettings = allSettings . sitemap || getDefaultSitemapSettings ( ) ;
41+ const globalCanonicalUrl : string | null = allSettings . global_canonical_url || null ;
5742
5843 // If sitemap is disabled, return 404
5944 if ( settings . mode === 'none' ) {
@@ -71,7 +56,7 @@ export async function GET() {
7156 }
7257
7358 // Auto-generate sitemap
74- const baseUrl = getBaseUrl ( ) ;
59+ const baseUrl = getSiteBaseUrl ( { globalCanonicalUrl } ) || '' ;
7560
7661 // Fetch published pages and folders
7762 const [ pages , folders , locales ] = await Promise . all ( [
0 commit comments