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
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
This commit is contained in:
126
lib/blog.ts
126
lib/blog.ts
@@ -57,64 +57,23 @@ export function isPostVisible(post: { frontmatter: { date: string; public?: bool
|
||||
}
|
||||
|
||||
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({
|
||||
collection: 'posts',
|
||||
where: {
|
||||
slug: { equals: slug },
|
||||
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,
|
||||
const { docs } = await payload.find({
|
||||
collection: 'posts',
|
||||
where: {
|
||||
slug: { equals: slug },
|
||||
locale: { equals: locale },
|
||||
},
|
||||
},
|
||||
sort: '-date',
|
||||
draft: process.env.NODE_ENV === 'development', // Includes Drafts if running locally
|
||||
limit: 100,
|
||||
});
|
||||
draft: process.env.NODE_ENV === 'development',
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
if (!docs || docs.length === 0) return null;
|
||||
|
||||
const doc = docs[0];
|
||||
|
||||
return docs.map((doc) => {
|
||||
return {
|
||||
slug: doc.slug,
|
||||
frontmatter: {
|
||||
@@ -135,11 +94,62 @@ export async function getAllPosts(locale: string): Promise<PostMdx[]> {
|
||||
typeof doc.featuredImage === 'object' && doc.featuredImage !== null
|
||||
? doc.featuredImage.focalY
|
||||
: 50,
|
||||
public: doc._status === 'published',
|
||||
} as PostFrontmatter,
|
||||
// Pass the Lexical content object rather than raw markdown string
|
||||
content: doc.content as any,
|
||||
content: doc.content as any, // Native Lexical Editor State
|
||||
};
|
||||
});
|
||||
} 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>[]> {
|
||||
|
||||
Reference in New Issue
Block a user