feat: migrate Payload CMS to MDX and harden static infrastructure
This commit is contained in:
@@ -1,18 +1,28 @@
|
||||
import React from 'react';
|
||||
import { getPayload } from 'payload';
|
||||
import configPromise from '@payload-config';
|
||||
import { Heading } from '@/components/ui';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import matter from 'gray-matter';
|
||||
|
||||
export const AgbHistoryBlock: React.FC<{ title: string }> = async ({ title }) => {
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
const agbs: any[] = [];
|
||||
try {
|
||||
const dir = path.join(process.cwd(), 'content', 'agbs');
|
||||
const files = await fs.readdir(dir);
|
||||
for (const f of files) {
|
||||
if (!f.endsWith('.mdx')) continue;
|
||||
const fileContent = await fs.readFile(path.join(dir, f), 'utf-8');
|
||||
const { data } = matter(fileContent);
|
||||
agbs.push({ id: f, ...data });
|
||||
}
|
||||
agbs.sort(
|
||||
(a, b) => new Date(b.versionDate || 0).getTime() - new Date(a.versionDate || 0).getTime(),
|
||||
);
|
||||
} catch (err) {
|
||||
console.error('Failed reading AGBs from MDX:', err);
|
||||
}
|
||||
|
||||
const agbs = await payload.find({
|
||||
collection: 'agbs-collection',
|
||||
sort: '-versionDate',
|
||||
limit: 100,
|
||||
});
|
||||
|
||||
if (agbs.totalDocs === 0) {
|
||||
if (agbs.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -22,15 +32,15 @@ export const AgbHistoryBlock: React.FC<{ title: string }> = async ({ title }) =>
|
||||
{title || 'Vorherige Versionen'}
|
||||
</Heading>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
{agbs.docs.map((agb: any) => {
|
||||
{agbs.map((agb: any) => {
|
||||
const date = new Date(agb.versionDate).toLocaleDateString('de-DE', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
});
|
||||
|
||||
const fileUrl = typeof agb.file === 'object' ? agb.file.url : '';
|
||||
const filename = typeof agb.file === 'object' ? agb.file.filename : 'agb.pdf';
|
||||
const fileUrl = agb.file?.url || agb.fileUrl || '';
|
||||
const filename = agb.file?.filename || agb.filename || 'agb.pdf';
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user