Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 44d3e8585b |
@@ -5,12 +5,10 @@ import { getAllPostsMetadata } from '@/lib/blog';
|
|||||||
import { getAllPagesMetadata } from '@/lib/pages';
|
import { getAllPagesMetadata } from '@/lib/pages';
|
||||||
import { mapFileSlugToTranslated } from '@/lib/slugs';
|
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> {
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||||
const baseUrl = process.env.CI
|
const baseUrl = config.baseUrl || 'https://klz-cables.com';
|
||||||
? 'http://klz.localhost'
|
|
||||||
: config.baseUrl || 'https://klz-cables.com';
|
|
||||||
const locales = ['de', 'en'];
|
const locales = ['de', 'en'];
|
||||||
|
|
||||||
const sitemapEntries: MetadataRoute.Sitemap = [];
|
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,
|
limit: 100,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(`[Payload] getAllPosts for ${locale}: Found ${docs.length} docs`);
|
||||||
|
|
||||||
return docs.map((doc) => {
|
return docs.map((doc) => {
|
||||||
return {
|
return {
|
||||||
slug: doc.slug,
|
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,
|
select: selectFields,
|
||||||
});
|
});
|
||||||
|
|
||||||
let products: ProductMdx[] = result.docs
|
console.log(`[Payload] getAllProducts for ${locale}: Found ${result.docs.length} 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[];
|
|
||||||
|
|
||||||
const plainCategories = Array.isArray(doc.categories)
|
let products: ProductMdx[] = result.docs.map((doc) => {
|
||||||
? doc.categories.map((c: any) => String(c.category))
|
const resolvedImages = ((doc.images as any[]) || [])
|
||||||
: [];
|
.map((img) => (typeof img === 'string' ? img : img.url))
|
||||||
|
.filter(Boolean) as string[];
|
||||||
|
|
||||||
return {
|
const plainCategories = Array.isArray(doc.categories)
|
||||||
slug: String(doc.slug),
|
? doc.categories.map((c: any) => String(c.category))
|
||||||
frontmatter: {
|
: [];
|
||||||
title: String(doc.title),
|
|
||||||
sku: doc.sku ? String(doc.sku) : '',
|
return {
|
||||||
description: doc.description ? String(doc.description) : '',
|
slug: String(doc.slug),
|
||||||
categories: plainCategories,
|
frontmatter: {
|
||||||
images: resolvedImages,
|
title: String(doc.title),
|
||||||
locale: String(doc.locale),
|
sku: doc.sku ? String(doc.sku) : '',
|
||||||
},
|
description: doc.description ? String(doc.description) : '',
|
||||||
content: null,
|
categories: plainCategories,
|
||||||
};
|
images: resolvedImages,
|
||||||
});
|
locale: String(doc.locale),
|
||||||
|
},
|
||||||
|
content: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Also include English fallbacks for slugs not in this locale
|
// Also include English fallbacks for slugs not in this locale
|
||||||
if (locale !== 'en') {
|
if (locale !== 'en') {
|
||||||
@@ -227,14 +222,12 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
|||||||
select: selectFields,
|
select: selectFields,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`[Payload] getAllProducts (en fallbacks) for ${locale}: Found ${enResult.docs.length} docs`,
|
||||||
|
);
|
||||||
|
|
||||||
const fallbacks = enResult.docs
|
const fallbacks = enResult.docs
|
||||||
.filter((doc) => !localeSlugs.has(doc.slug))
|
.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) => {
|
.map((doc) => {
|
||||||
const resolvedImages = ((doc.images as any[]) || [])
|
const resolvedImages = ((doc.images as any[]) || [])
|
||||||
.map((img) => (typeof img === 'string' ? img : img.url))
|
.map((img) => (typeof img === 'string' ? img : img.url))
|
||||||
|
|||||||
Reference in New Issue
Block a user