Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 6s
Build & Deploy / 🧪 QA (push) Failing after 55s
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
- Switch embedding API from OpenRouter to Mistral mistral-embed (1024-dim, EU/DSGVO) - Add afterChange/afterDelete hooks to Posts.ts and Pages.ts for live sync - Integrate kabelhandbuch.txt parsing into /api/sync-qdrant boot route - Add .gitignore entries for kabelhandbuch.txt
151 lines
3.9 KiB
TypeScript
151 lines
3.9 KiB
TypeScript
import { CollectionConfig } from 'payload';
|
|
import { lexicalEditor, BlocksFeature } from '@payloadcms/richtext-lexical';
|
|
import { payloadBlocks } from '../blocks/allBlocks';
|
|
|
|
export const Pages: CollectionConfig = {
|
|
slug: 'pages',
|
|
admin: {
|
|
useAsTitle: 'title',
|
|
defaultColumns: ['title', 'slug', 'layout', '_status', 'updatedAt'],
|
|
},
|
|
versions: {
|
|
drafts: true,
|
|
},
|
|
access: {
|
|
read: ({ req: { user } }) => {
|
|
if (process.env.NODE_ENV === 'development' || process.env.TARGET === 'staging') {
|
|
return true;
|
|
}
|
|
if (user) {
|
|
return true;
|
|
}
|
|
return {
|
|
_status: {
|
|
equals: 'published',
|
|
},
|
|
};
|
|
},
|
|
},
|
|
hooks: {
|
|
afterChange: [
|
|
async ({ doc, req }) => {
|
|
// Run index sync asynchronously to not block the CMS save operation
|
|
setTimeout(async () => {
|
|
try {
|
|
const { upsertProductVector, deleteProductVector } = await import('../../lib/qdrant');
|
|
|
|
// Check if page is published
|
|
if (doc._status !== 'published') {
|
|
await deleteProductVector(`page_${doc.id}`);
|
|
req.payload.logger.info(`Removed drafted page ${doc.slug} from Qdrant`);
|
|
} else {
|
|
// Serialize payload
|
|
const contentText = [
|
|
`Seite: ${doc.title}`,
|
|
doc.excerpt ? `Beschreibung: ${doc.excerpt}` : '',
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n');
|
|
|
|
const payload = {
|
|
type: 'knowledge',
|
|
content: contentText,
|
|
data: {
|
|
title: doc.title,
|
|
slug: doc.slug,
|
|
},
|
|
};
|
|
|
|
await upsertProductVector(`page_${doc.id}`, contentText, payload);
|
|
req.payload.logger.info(`Upserted page ${doc.slug} to Qdrant`);
|
|
}
|
|
} catch (error) {
|
|
req.payload.logger.error({
|
|
msg: 'Error syncing page to Qdrant',
|
|
err: error,
|
|
pageId: doc.id,
|
|
});
|
|
}
|
|
}, 0);
|
|
return doc;
|
|
},
|
|
],
|
|
afterDelete: [
|
|
async ({ id, req }) => {
|
|
try {
|
|
const { deleteProductVector } = await import('../../lib/qdrant');
|
|
await deleteProductVector(`page_${id}`);
|
|
req.payload.logger.info(`Deleted page ${id} from Qdrant`);
|
|
} catch (error) {
|
|
req.payload.logger.error({
|
|
msg: 'Error deleting page from Qdrant',
|
|
err: error,
|
|
pageId: id,
|
|
});
|
|
}
|
|
},
|
|
],
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'title',
|
|
type: 'text',
|
|
required: true,
|
|
localized: true,
|
|
},
|
|
{
|
|
name: 'slug',
|
|
type: 'text',
|
|
required: true,
|
|
localized: true,
|
|
admin: {
|
|
position: 'sidebar',
|
|
description: 'The URL slug for this locale (e.g. "impressum" for DE, "imprint" for EN).',
|
|
},
|
|
},
|
|
{
|
|
name: 'layout',
|
|
type: 'select',
|
|
defaultValue: 'default',
|
|
options: [
|
|
{ label: 'Default (Article)', value: 'default' },
|
|
{ label: 'Full Bleed (Blocks Only)', value: 'fullBleed' },
|
|
],
|
|
admin: {
|
|
position: 'sidebar',
|
|
description: 'Full Bleed pages render blocks edge-to-edge without a generic hero wrapper.',
|
|
},
|
|
},
|
|
{
|
|
name: 'excerpt',
|
|
type: 'textarea',
|
|
localized: true,
|
|
admin: {
|
|
position: 'sidebar',
|
|
},
|
|
},
|
|
{
|
|
name: 'featuredImage',
|
|
type: 'upload',
|
|
relationTo: 'media',
|
|
admin: {
|
|
position: 'sidebar',
|
|
},
|
|
},
|
|
{
|
|
name: 'content',
|
|
type: 'richText',
|
|
localized: true,
|
|
editor: lexicalEditor({
|
|
features: ({ defaultFeatures }) => [
|
|
...defaultFeatures,
|
|
BlocksFeature({
|
|
blocks: payloadBlocks,
|
|
}),
|
|
],
|
|
}),
|
|
required: true,
|
|
},
|
|
],
|
|
};
|