Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 10s
Build & Deploy / 🧪 QA (push) Failing after 2m24s
Build & Deploy / 🏗️ Build (push) Failing after 3m40s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 3s
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { getPayload } from "payload";
|
|
import configPromise from "@payload-config";
|
|
|
|
export async function getAllPosts() {
|
|
if (!process.env.DATABASE_URI && !process.env.POSTGRES_URI) {
|
|
console.warn(
|
|
"⚠️ Bypassing Payload fetch during Next.js build: DATABASE_URI is missing.",
|
|
);
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
const payload = await getPayload({ config: configPromise });
|
|
const { docs } = await payload.find({
|
|
collection: "posts",
|
|
limit: 1000,
|
|
sort: "-date",
|
|
where: {
|
|
and: [
|
|
{
|
|
_status: {
|
|
equals: "published",
|
|
},
|
|
},
|
|
{
|
|
date: {
|
|
less_than_equal: new Date(),
|
|
},
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
return docs.map((doc) => ({
|
|
title: doc.title as string,
|
|
description: doc.description as string,
|
|
date: doc.date as string,
|
|
tags: (doc.tags || []).map((t) =>
|
|
typeof t === "object" && t !== null ? t.tag : t,
|
|
) as string[],
|
|
slug: doc.slug as string,
|
|
thumbnail:
|
|
(doc.featuredImage &&
|
|
typeof doc.featuredImage === "object" &&
|
|
doc.featuredImage.url
|
|
? doc.featuredImage.url
|
|
: "") || "",
|
|
body: { code: "" as string },
|
|
lexicalContent: doc.content || null,
|
|
}));
|
|
} catch (error) {
|
|
console.warn(
|
|
"⚠️ Bypassing Payload fetch during build: Database connection refused.",
|
|
error,
|
|
);
|
|
return [];
|
|
}
|
|
}
|