From 44d3e8585b2e2c8eb6658044a539331770422ab4 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 25 Feb 2026 12:48:29 +0100 Subject: [PATCH] fix: make sitemap dynamic, fix baseUrl logic, and relax product image filter --- app/sitemap.ts | 6 ++--- debug-sitemap.ts | 47 ++++++++++++++++++++++++++++++++++++++ lib/blog.ts | 2 ++ lib/mdx.ts | 59 +++++++++++++++++++++--------------------------- 4 files changed, 77 insertions(+), 37 deletions(-) create mode 100644 debug-sitemap.ts diff --git a/app/sitemap.ts b/app/sitemap.ts index 7ddb4107..d4a455bc 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -5,12 +5,10 @@ import { getAllPostsMetadata } from '@/lib/blog'; import { getAllPagesMetadata } from '@/lib/pages'; import { mapFileSlugToTranslated } from '@/lib/slugs'; -export const revalidate = 3600; // Revalidate every hour +export const dynamic = 'force-dynamic'; export default async function sitemap(): Promise { - const baseUrl = process.env.CI - ? 'http://klz.localhost' - : config.baseUrl || 'https://klz-cables.com'; + const baseUrl = config.baseUrl || 'https://klz-cables.com'; const locales = ['de', 'en']; const sitemapEntries: MetadataRoute.Sitemap = []; diff --git a/debug-sitemap.ts b/debug-sitemap.ts new file mode 100644 index 00000000..60a2b3d3 --- /dev/null +++ b/debug-sitemap.ts @@ -0,0 +1,47 @@ +console.log('DEBUG SCRIPT STARTING...'); + +async function debug() { + console.log('Importing dependencies...'); + try { + const { getAllProductsMetadata } = await import('./lib/mdx'); + const { getAllPostsMetadata } = await import('./lib/blog'); + const { getAllPagesMetadata } = await import('./lib/pages'); + + console.log('Dependencies imported.'); + + const locales = ['de', 'en']; + for (const locale of locales) { + console.log(`--- Locale: ${locale} ---`); + + try { + const products = await getAllProductsMetadata(locale); + console.log(`Products (${locale}): ${products.length}`); + } catch (e) { + console.error(`Failed to get products for ${locale}:`, e); + } + + try { + const posts = await getAllPostsMetadata(locale); + console.log(`Posts (${locale}): ${posts.length}`); + } catch (e) { + console.error(`Failed to get posts for ${locale}:`, e); + } + + try { + const pages = await getAllPagesMetadata(locale); + console.log(`Pages (${locale}): ${pages.length}`); + } catch (e) { + console.error(`Failed to get pages for ${locale}:`, e); + } + } + } catch (err) { + console.error('Debug failed during setup/imports:', err); + } + console.log('DEBUG SCRIPT FINISHED.'); + process.exit(0); +} + +debug().catch((err) => { + console.error('Unhandled retransmission error in debug():', err); + process.exit(1); +}); diff --git a/lib/blog.ts b/lib/blog.ts index cd0f50c4..d7bd450c 100644 --- a/lib/blog.ts +++ b/lib/blog.ts @@ -123,6 +123,8 @@ export async function getAllPosts(locale: string): Promise { limit: 100, }); + console.log(`[Payload] getAllPosts for ${locale}: Found ${docs.length} docs`); + return docs.map((doc) => { return { slug: doc.slug, diff --git a/lib/mdx.ts b/lib/mdx.ts index c69addff..062978cd 100644 --- a/lib/mdx.ts +++ b/lib/mdx.ts @@ -186,35 +186,30 @@ export async function getAllProducts(locale: string): Promise { select: selectFields, }); - let products: ProductMdx[] = result.docs - .filter((doc) => { - const resolvedImages = ((doc.images as any[]) || []) - .map((img) => (typeof img === 'string' ? img : img.url)) - .filter(Boolean); - return resolvedImages.length > 0; - }) - .map((doc) => { - const resolvedImages = ((doc.images as any[]) || []) - .map((img) => (typeof img === 'string' ? img : img.url)) - .filter(Boolean) as string[]; + console.log(`[Payload] getAllProducts for ${locale}: Found ${result.docs.length} docs`); - const plainCategories = Array.isArray(doc.categories) - ? doc.categories.map((c: any) => String(c.category)) - : []; + let products: ProductMdx[] = result.docs.map((doc) => { + const resolvedImages = ((doc.images as any[]) || []) + .map((img) => (typeof img === 'string' ? img : img.url)) + .filter(Boolean) as string[]; - return { - slug: String(doc.slug), - frontmatter: { - title: String(doc.title), - sku: doc.sku ? String(doc.sku) : '', - description: doc.description ? String(doc.description) : '', - categories: plainCategories, - images: resolvedImages, - locale: String(doc.locale), - }, - content: null, - }; - }); + const plainCategories = Array.isArray(doc.categories) + ? doc.categories.map((c: any) => String(c.category)) + : []; + + return { + slug: String(doc.slug), + frontmatter: { + title: String(doc.title), + sku: doc.sku ? String(doc.sku) : '', + description: doc.description ? String(doc.description) : '', + categories: plainCategories, + images: resolvedImages, + locale: String(doc.locale), + }, + content: null, + }; + }); // Also include English fallbacks for slugs not in this locale if (locale !== 'en') { @@ -227,14 +222,12 @@ export async function getAllProducts(locale: string): Promise { select: selectFields, }); + console.log( + `[Payload] getAllProducts (en fallbacks) for ${locale}: Found ${enResult.docs.length} docs`, + ); + const fallbacks = enResult.docs .filter((doc) => !localeSlugs.has(doc.slug)) - .filter((doc) => { - const resolvedImages = ((doc.images as any[]) || []) - .map((img) => (typeof img === 'string' ? img : img.url)) - .filter(Boolean); - return resolvedImages.length > 0; - }) .map((doc) => { const resolvedImages = ((doc.images as any[]) || []) .map((img) => (typeof img === 'string' ? img : img.url))