feat: payload cms
This commit is contained in:
18
lib/blog.ts
18
lib/blog.ts
@@ -32,6 +32,8 @@ export interface PostFrontmatter {
|
||||
date: string;
|
||||
excerpt?: string;
|
||||
featuredImage?: string | null;
|
||||
focalX?: number;
|
||||
focalY?: number;
|
||||
category?: string;
|
||||
locale: string;
|
||||
public?: boolean;
|
||||
@@ -83,6 +85,14 @@ export async function getPostBySlug(slug: string, locale: string): Promise<PostM
|
||||
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
|
||||
@@ -117,6 +127,14 @@ export async function getAllPosts(locale: string): Promise<PostMdx[]> {
|
||||
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,
|
||||
|
||||
24
lib/mdx.ts
24
lib/mdx.ts
@@ -155,12 +155,23 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
||||
// Fetch ALL products in a single query to avoid N+1 getPayload() calls
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
|
||||
const selectFields = {
|
||||
title: true,
|
||||
slug: true,
|
||||
sku: true,
|
||||
description: true,
|
||||
categories: true,
|
||||
images: true,
|
||||
locale: true,
|
||||
};
|
||||
|
||||
// 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
|
||||
@@ -174,15 +185,15 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
||||
slug: doc.slug,
|
||||
frontmatter: {
|
||||
title: doc.title,
|
||||
sku: doc.sku,
|
||||
description: doc.description,
|
||||
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: doc.content,
|
||||
content: null, // Avoided loading into memory!
|
||||
}));
|
||||
|
||||
// Also include English fallbacks for slugs not in this locale
|
||||
@@ -193,6 +204,7 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
||||
where: { locale: { equals: 'en' } },
|
||||
depth: 1,
|
||||
pagination: false,
|
||||
select: selectFields,
|
||||
});
|
||||
|
||||
const fallbacks = enResult.docs
|
||||
@@ -207,8 +219,8 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
||||
slug: doc.slug,
|
||||
frontmatter: {
|
||||
title: doc.title,
|
||||
sku: doc.sku,
|
||||
description: doc.description,
|
||||
sku: doc.sku || '',
|
||||
description: doc.description || '',
|
||||
categories: Array.isArray(doc.categories)
|
||||
? doc.categories.map((c: any) => c.category)
|
||||
: [],
|
||||
@@ -218,7 +230,7 @@ export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
|
||||
locale: doc.locale,
|
||||
isFallback: true,
|
||||
},
|
||||
content: doc.content,
|
||||
content: null, // Avoided loading into memory!
|
||||
}));
|
||||
|
||||
products = [...products, ...fallbacks];
|
||||
|
||||
@@ -46,7 +46,7 @@ export class GlitchtipErrorReportingService implements ErrorReportingService {
|
||||
if (!this.sentryPromise) {
|
||||
this.sentryPromise = import('@sentry/nextjs').then((Sentry) => {
|
||||
// Client-side initialization must happen here since sentry.client.config.ts is empty
|
||||
if (typeof window !== 'undefined') {
|
||||
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'production') {
|
||||
Sentry.init({
|
||||
dsn: 'https://public@errors.infra.mintel.me/1',
|
||||
tunnel: '/errors/api/relay',
|
||||
|
||||
Reference in New Issue
Block a user