Compare commits

...

1 Commits

Author SHA1 Message Date
d57700d322 fix: build stability (added try-catch to payload queries and removed generateStaticParams from generic pages)
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 9s
Build & Deploy / 🧪 QA (push) Failing after 3m20s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🏗️ Build (push) Successful in 14m43s
Build & Deploy / 🧪 Smoke Test (push) Has been skipped
Build & Deploy / ⚡ Lighthouse (push) Has been skipped
Build & Deploy / ♿ WCAG (push) Has been skipped
Build & Deploy / 🛡️ Quality Gates (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 13s
2026-02-24 19:45:33 +01:00
6 changed files with 292 additions and 262 deletions

View File

@@ -14,20 +14,6 @@ interface PageProps {
}>; }>;
} }
export async function generateStaticParams() {
const locales = ['en', 'de'];
const params = [];
for (const locale of locales) {
const pages = await getAllPages(locale);
for (const page of pages) {
params.push({ locale, slug: page.slug });
}
}
return params;
}
export async function generateMetadata({ params }: PageProps): Promise<Metadata> { export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
const { locale, slug } = await params; const { locale, slug } = await params;
const pageData = await getPageBySlug(slug, locale); const pageData = await getPageBySlug(slug, locale);

View File

@@ -57,64 +57,23 @@ export function isPostVisible(post: { frontmatter: { date: string; public?: bool
} }
export async function getPostBySlug(slug: string, locale: string): Promise<PostMdx | null> { export async function getPostBySlug(slug: string, locale: string): Promise<PostMdx | null> {
const payload = await getPayload({ config: configPromise }); try {
const payload = await getPayload({ config: configPromise });
const { docs } = await payload.find({ const { docs } = await payload.find({
collection: 'posts', collection: 'posts',
where: { where: {
slug: { equals: slug }, slug: { equals: slug },
locale: { equals: locale }, locale: { equals: locale },
},
draft: process.env.NODE_ENV === 'development',
limit: 1,
});
if (!docs || docs.length === 0) return null;
const doc = docs[0];
return {
slug: doc.slug,
frontmatter: {
title: doc.title,
date: doc.date,
excerpt: doc.excerpt || '',
category: doc.category || '',
locale: doc.locale,
featuredImage:
typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.sizes?.card?.url || doc.featuredImage.url
: null,
focalX:
typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.focalX
: 50,
focalY:
typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.focalY
: 50,
public: doc._status === 'published',
} as PostFrontmatter,
content: doc.content as any, // Native Lexical Editor State
};
}
export async function getAllPosts(locale: string): Promise<PostMdx[]> {
const payload = await getPayload({ config: configPromise });
// Query only published posts (access checks applied automatically by Payload!)
const { docs } = await payload.find({
collection: 'posts',
where: {
locale: {
equals: locale,
}, },
}, draft: process.env.NODE_ENV === 'development',
sort: '-date', limit: 1,
draft: process.env.NODE_ENV === 'development', // Includes Drafts if running locally });
limit: 100,
}); if (!docs || docs.length === 0) return null;
const doc = docs[0];
return docs.map((doc) => {
return { return {
slug: doc.slug, slug: doc.slug,
frontmatter: { frontmatter: {
@@ -135,11 +94,62 @@ export async function getAllPosts(locale: string): Promise<PostMdx[]> {
typeof doc.featuredImage === 'object' && doc.featuredImage !== null typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.focalY ? doc.featuredImage.focalY
: 50, : 50,
public: doc._status === 'published',
} as PostFrontmatter, } as PostFrontmatter,
// Pass the Lexical content object rather than raw markdown string content: doc.content as any, // Native Lexical Editor State
content: doc.content as any,
}; };
}); } catch (error) {
console.error(`[Payload] getPostBySlug failed for ${slug}:`, error);
return null;
}
}
export async function getAllPosts(locale: string): Promise<PostMdx[]> {
try {
const payload = await getPayload({ config: configPromise });
// Query only published posts (access checks applied automatically by Payload!)
const { docs } = await payload.find({
collection: 'posts',
where: {
locale: {
equals: locale,
},
},
sort: '-date',
draft: process.env.NODE_ENV === 'development', // Includes Drafts if running locally
limit: 100,
});
return docs.map((doc) => {
return {
slug: doc.slug,
frontmatter: {
title: doc.title,
date: doc.date,
excerpt: doc.excerpt || '',
category: doc.category || '',
locale: doc.locale,
featuredImage:
typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.sizes?.card?.url || doc.featuredImage.url
: null,
focalX:
typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.focalX
: 50,
focalY:
typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.focalY
: 50,
} as PostFrontmatter,
// Pass the Lexical content object rather than raw markdown string
content: doc.content as any,
};
});
} catch (error) {
console.error(`[Payload] getAllPosts failed for ${locale}:`, error);
return [];
}
} }
export async function getAllPostsMetadata(locale: string): Promise<Partial<PostMdx>[]> { export async function getAllPostsMetadata(locale: string): Promise<Partial<PostMdx>[]> {

View File

@@ -79,135 +79,114 @@ export async function getProductMetadata(
} }
export async function getProductBySlug(slug: string, locale: string): Promise<ProductMdx | null> { export async function getProductBySlug(slug: string, locale: string): Promise<ProductMdx | null> {
const payload = await getPayload({ config: configPromise }); try {
const fileSlug = await mapSlugToFileSlug(slug, locale); const payload = await getPayload({ config: configPromise });
const fileSlug = await mapSlugToFileSlug(slug, locale);
let result = await payload.find({ let result = await payload.find({
collection: 'products',
where: {
and: [{ slug: { equals: fileSlug } }, { locale: { equals: locale } }],
},
depth: 1, // Auto-resolve Media logic
limit: 1,
});
let isFallback = false;
if (result.docs.length === 0 && locale !== 'en') {
// Fallback to English
result = await payload.find({
collection: 'products', collection: 'products',
where: { where: {
and: [{ slug: { equals: fileSlug } }, { locale: { equals: 'en' } }], and: [{ slug: { equals: fileSlug } }, { locale: { equals: locale } }],
}, },
depth: 1, depth: 1, // Auto-resolve Media logic
limit: 1, limit: 1,
}); });
if (result.docs.length > 0) {
isFallback = true; let isFallback = false;
if (result.docs.length === 0 && locale !== 'en') {
// Fallback to English
result = await payload.find({
collection: 'products',
where: {
and: [{ slug: { equals: fileSlug } }, { locale: { equals: 'en' } }],
},
depth: 1,
limit: 1,
});
if (result.docs.length > 0) {
isFallback = true;
}
} }
}
if (result.docs.length > 0) { if (result.docs.length > 0) {
const doc = result.docs[0]; const doc = result.docs[0];
// Map Images correctly from resolved Media docs // Map Images correctly from resolved Media docs
const resolvedImages = ((doc.images as any[]) || [])
.map((img) => (typeof img === 'string' ? img : img.url))
.filter(Boolean);
if (resolvedImages.length === 0) return null;
return {
slug: doc.slug,
frontmatter: {
title: doc.title,
sku: doc.sku,
description: doc.description,
categories: Array.isArray(doc.categories) ? doc.categories.map((c: any) => c.category) : [],
images: resolvedImages,
locale: doc.locale,
isFallback,
},
content: doc.content, // Lexical payload instead of raw MDX String
};
}
return null;
}
export async function getAllProductSlugs(locale: string): Promise<string[]> {
const payload = await getPayload({ config: configPromise });
const result = await payload.find({
collection: 'products',
where: {
locale: {
equals: locale,
},
},
pagination: false, // get all docs
});
return result.docs.map((doc) => doc.slug);
}
export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
const payload = await getPayload({ config: configPromise });
const selectFields = {
title: true,
slug: true,
sku: true,
description: true,
categories: true,
images: true,
locale: true,
} as const;
// Get products for this locale
const result = await payload.find({
collection: 'products',
where: { locale: { equals: locale } },
depth: 1,
pagination: false,
select: selectFields,
});
let products: ProductMdx[] = result.docs
.filter((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))
.filter(Boolean); .filter(Boolean);
return resolvedImages.length > 0;
})
.map((doc) => ({
slug: doc.slug,
frontmatter: {
title: doc.title,
sku: doc.sku || '',
description: doc.description || '',
categories: Array.isArray(doc.categories) ? doc.categories.map((c: any) => c.category) : [],
images: ((doc.images as any[]) || [])
.map((img) => (typeof img === 'string' ? img : img.url))
.filter(Boolean),
locale: doc.locale,
},
content: null,
}));
// Also include English fallbacks for slugs not in this locale if (resolvedImages.length === 0) return null;
if (locale !== 'en') {
const localeSlugs = new Set(products.map((p) => p.slug)); return {
const enResult = await payload.find({ slug: doc.slug,
frontmatter: {
title: doc.title,
sku: doc.sku,
description: doc.description,
categories: Array.isArray(doc.categories)
? doc.categories.map((c: any) => c.category)
: [],
images: resolvedImages,
locale: doc.locale,
isFallback,
},
content: doc.content, // Lexical payload instead of raw MDX String
};
}
return null;
} catch (error) {
console.error(`[Payload] getProductBySlug failed for ${slug}:`, error);
return null;
}
}
export async function getAllProductSlugs(locale: string): Promise<string[]> {
try {
const payload = await getPayload({ config: configPromise });
const result = await payload.find({
collection: 'products', collection: 'products',
where: { locale: { equals: 'en' } }, where: {
locale: {
equals: locale,
},
},
pagination: false, // get all docs
});
return result.docs.map((doc) => doc.slug);
} catch (error) {
console.error(`[Payload] getAllProductSlugs failed for ${locale}:`, error);
return [];
}
}
export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
try {
const payload = await getPayload({ config: configPromise });
const selectFields = {
title: true,
slug: true,
sku: true,
description: true,
categories: true,
images: true,
locale: true,
} as const;
// Get products for this locale
const result = await payload.find({
collection: 'products',
where: { locale: { equals: locale } },
depth: 1, depth: 1,
pagination: false, pagination: false,
select: selectFields, select: selectFields,
}); });
const fallbacks = enResult.docs let products: ProductMdx[] = result.docs
.filter((doc) => !localeSlugs.has(doc.slug))
.filter((doc) => { .filter((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))
@@ -227,15 +206,55 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
.map((img) => (typeof img === 'string' ? img : img.url)) .map((img) => (typeof img === 'string' ? img : img.url))
.filter(Boolean), .filter(Boolean),
locale: doc.locale, locale: doc.locale,
isFallback: true,
}, },
content: null, content: null,
})); }));
products = [...products, ...fallbacks]; // Also include English fallbacks for slugs not in this locale
} if (locale !== 'en') {
const localeSlugs = new Set(products.map((p) => p.slug));
const enResult = await payload.find({
collection: 'products',
where: { locale: { equals: 'en' } },
depth: 1,
pagination: false,
select: selectFields,
});
return products; 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) => ({
slug: doc.slug,
frontmatter: {
title: doc.title,
sku: doc.sku || '',
description: doc.description || '',
categories: Array.isArray(doc.categories)
? doc.categories.map((c: any) => c.category)
: [],
images: ((doc.images as any[]) || [])
.map((img) => (typeof img === 'string' ? img : img.url))
.filter(Boolean),
locale: doc.locale,
isFallback: true,
},
content: null,
}));
products = [...products, ...fallbacks];
}
return products;
} catch (error) {
console.error(`[Payload] getAllProducts failed for ${locale}:`, error);
return [];
}
} }
export async function getAllProductsMetadata(locale: string): Promise<Partial<ProductMdx>[]> { export async function getAllProductsMetadata(locale: string): Promise<Partial<ProductMdx>[]> {

View File

@@ -16,97 +16,112 @@ export interface PageMdx {
} }
export async function getPageBySlug(slug: string, locale: string): Promise<PageMdx | null> { export async function getPageBySlug(slug: string, locale: string): Promise<PageMdx | null> {
const payload = await getPayload({ config: configPromise }); try {
const payload = await getPayload({ config: configPromise });
const result = await payload.find({ const result = await payload.find({
collection: 'pages' as any, collection: 'pages' as any,
where: { where: {
slug: { equals: slug }, slug: { equals: slug },
locale: { equals: locale }, locale: { equals: locale },
}, },
limit: 1, limit: 1,
}); });
const docs = result.docs as any[]; const docs = result.docs as any[];
if (!docs || docs.length === 0) return null; if (!docs || docs.length === 0) return null;
const doc = docs[0]; const doc = docs[0];
return { return {
slug: doc.slug, slug: doc.slug,
frontmatter: { frontmatter: {
title: doc.title, title: doc.title,
excerpt: doc.excerpt || '', excerpt: doc.excerpt || '',
locale: doc.locale, locale: doc.locale,
featuredImage: featuredImage:
typeof doc.featuredImage === 'object' && doc.featuredImage !== null typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.sizes?.card?.url || doc.featuredImage.url ? doc.featuredImage.sizes?.card?.url || doc.featuredImage.url
: null, : null,
} as PageFrontmatter, } as PageFrontmatter,
content: doc.content as any, // Native Lexical Editor State content: doc.content as any, // Native Lexical Editor State
}; };
} catch (error) {
console.error(`[Payload] getPageBySlug failed for ${slug}:`, error);
return null;
}
} }
export async function getAllPages(locale: string): Promise<PageMdx[]> { export async function getAllPages(locale: string): Promise<PageMdx[]> {
const payload = await getPayload({ config: configPromise }); try {
const payload = await getPayload({ config: configPromise });
const result = await payload.find({ const result = await payload.find({
collection: 'pages' as any, collection: 'pages' as any,
where: { where: {
locale: { locale: {
equals: locale, equals: locale,
},
}, },
}, limit: 100,
limit: 100, });
});
const docs = result.docs as any[]; const docs = result.docs as any[];
return docs.map((doc: any) => { return docs.map((doc: any) => {
return { return {
slug: doc.slug, slug: doc.slug,
frontmatter: { frontmatter: {
title: doc.title, title: doc.title,
excerpt: doc.excerpt || '', excerpt: doc.excerpt || '',
locale: doc.locale, locale: doc.locale,
featuredImage: featuredImage:
typeof doc.featuredImage === 'object' && doc.featuredImage !== null typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.sizes?.card?.url || doc.featuredImage.url ? doc.featuredImage.sizes?.card?.url || doc.featuredImage.url
: null, : null,
} as PageFrontmatter, } as PageFrontmatter,
content: doc.content as any, content: doc.content as any,
}; };
}); });
} catch (error) {
console.error(`[Payload] getAllPages failed for ${locale}:`, error);
return [];
}
} }
export async function getAllPagesMetadata(locale: string): Promise<Partial<PageMdx>[]> { export async function getAllPagesMetadata(locale: string): Promise<Partial<PageMdx>[]> {
const payload = await getPayload({ config: configPromise }); try {
const payload = await getPayload({ config: configPromise });
const result = await payload.find({ const result = await payload.find({
collection: 'pages' as any, collection: 'pages' as any,
where: { where: {
locale: { locale: {
equals: locale, equals: locale,
},
}, },
}, limit: 100,
limit: 100, });
});
const docs = result.docs as any[]; const docs = result.docs as any[];
return docs.map((doc: any) => { return docs.map((doc: any) => {
return { return {
slug: doc.slug, slug: doc.slug,
frontmatter: { frontmatter: {
title: doc.title, title: doc.title,
excerpt: doc.excerpt || '', excerpt: doc.excerpt || '',
locale: doc.locale, locale: doc.locale,
featuredImage: featuredImage:
typeof doc.featuredImage === 'object' && doc.featuredImage !== null typeof doc.featuredImage === 'object' && doc.featuredImage !== null
? doc.featuredImage.sizes?.card?.url || doc.featuredImage.url ? doc.featuredImage.sizes?.card?.url || doc.featuredImage.url
: null, : null,
} as PageFrontmatter, } as PageFrontmatter,
}; };
}); });
} catch (error) {
console.error(`[Payload] getAllPagesMetadata failed for ${locale}:`, error);
return [];
}
} }

2
next-env.d.ts vendored
View File

@@ -1,6 +1,6 @@
/// <reference types="next" /> /// <reference types="next" />
/// <reference types="next/image-types/global" /> /// <reference types="next/image-types/global" />
import "./.next/dev/types/routes.d.ts"; import "./.next/types/routes.d.ts";
// NOTE: This file should not be edited // NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information. // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

View File

@@ -136,7 +136,7 @@
"prepare": "husky", "prepare": "husky",
"preinstall": "npx only-allow pnpm" "preinstall": "npx only-allow pnpm"
}, },
"version": "2.0.0", "version": "2.0.1",
"pnpm": { "pnpm": {
"onlyBuiltDependencies": [ "onlyBuiltDependencies": [
"@parcel/watcher", "@parcel/watcher",