fix: make sitemap dynamic, fix baseUrl logic, and relax product image filter
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 13s
Build & Deploy / 🧪 QA (push) Successful in 2m18s
Build & Deploy / 🏗️ Build (push) Successful in 5m49s
Build & Deploy / 🚀 Deploy (push) Successful in 23s
Build & Deploy / 🧪 Post-Deploy Verification (push) Failing after 2m19s
Build & Deploy / ⚡ Performance & Accessibility (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 1s
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 13s
Build & Deploy / 🧪 QA (push) Successful in 2m18s
Build & Deploy / 🏗️ Build (push) Successful in 5m49s
Build & Deploy / 🚀 Deploy (push) Successful in 23s
Build & Deploy / 🧪 Post-Deploy Verification (push) Failing after 2m19s
Build & Deploy / ⚡ Performance & Accessibility (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 1s
This commit is contained in:
@@ -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<MetadataRoute.Sitemap> {
|
||||
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 = [];
|
||||
|
||||
47
debug-sitemap.ts
Normal file
47
debug-sitemap.ts
Normal file
@@ -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);
|
||||
});
|
||||
@@ -123,6 +123,8 @@ export async function getAllPosts(locale: string): Promise<PostMdx[]> {
|
||||
limit: 100,
|
||||
});
|
||||
|
||||
console.log(`[Payload] getAllPosts for ${locale}: Found ${docs.length} docs`);
|
||||
|
||||
return docs.map((doc) => {
|
||||
return {
|
||||
slug: doc.slug,
|
||||
|
||||
59
lib/mdx.ts
59
lib/mdx.ts
@@ -186,35 +186,30 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
||||
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<ProductMdx[]> {
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user