feat: setup globals (Footer), sqlite migration, seed update and access rules
This commit is contained in:
+137
@@ -0,0 +1,137 @@
|
||||
import { getPayload } from 'payload'
|
||||
import configPromise from '../src/payload.config'
|
||||
import { toSlug } from '@intecion/ipal-kit'
|
||||
|
||||
const PAGES = [
|
||||
{ pl: 'Strona główna', de: 'Startseite', isHome: true },
|
||||
{ pl: 'Usługi', de: 'Leistungen', isHome: false },
|
||||
{ pl: 'Jak się umówić', de: 'Terminvereinbarung', isHome: false },
|
||||
{ pl: 'O mnie', de: 'Über mich', isHome: false },
|
||||
{ pl: 'FAQ', de: 'FAQ', isHome: false },
|
||||
{ pl: 'Kontakt', de: 'Kontakt', isHome: false },
|
||||
{ pl: 'Stowarzyszenie', de: 'Verein', isHome: false },
|
||||
{ pl: 'Polityka prywatności', de: 'Datenschutzerklärung', isHome: false },
|
||||
{ pl: 'Polityka cookies', de: 'Cookie-Richtlinie', isHome: false },
|
||||
{ pl: 'Impressum', de: 'Impressum', isHome: false },
|
||||
];
|
||||
|
||||
async function run() {
|
||||
const payload = await getPayload({ config: configPromise })
|
||||
|
||||
const existingPages = await payload.find({
|
||||
collection: 'pages',
|
||||
limit: 1,
|
||||
})
|
||||
|
||||
if (existingPages.totalDocs === 0) {
|
||||
console.log('Seeding pages...')
|
||||
|
||||
const pageIds: number[] = [];
|
||||
|
||||
for (const page of PAGES) {
|
||||
// @ts-ignore
|
||||
const createdPage = await payload.create({
|
||||
collection: 'pages',
|
||||
data: {
|
||||
title: page.pl,
|
||||
slug: page.isHome ? 'home' : toSlug(page.pl),
|
||||
layout: [
|
||||
{
|
||||
blockType: 'TextSection',
|
||||
text: page.isHome
|
||||
? 'Witaj na nowej stronie głównej opartej o mechanizm klocków (blocks) i Payload CMS.'
|
||||
: 'Treść w przygotowaniu',
|
||||
}
|
||||
]
|
||||
},
|
||||
locale: 'pl',
|
||||
});
|
||||
|
||||
// Rzutowanie na number: Payload domyślnie może traktować ID jako 'string | number',
|
||||
// jednak przy adapterze Postgres (domyślnie serial) ID to zawsze 'number',
|
||||
// czego z kolei ściśle wymaga pole relacyjne w updateGlobal.
|
||||
pageIds.push(createdPage.id as unknown as number);
|
||||
|
||||
// @ts-ignore
|
||||
await payload.update({
|
||||
collection: 'pages',
|
||||
id: createdPage.id,
|
||||
data: {
|
||||
title: page.de,
|
||||
slug: page.isHome ? 'home' : toSlug(page.de),
|
||||
layout: [
|
||||
{
|
||||
blockType: 'TextSection',
|
||||
text: page.isHome
|
||||
? 'Willkommen auf der neuen Startseite basierend auf dem Blöcke-Mechanismus und Payload CMS.'
|
||||
: 'Inhalt in Vorbereitung',
|
||||
}
|
||||
]
|
||||
},
|
||||
locale: 'de',
|
||||
});
|
||||
|
||||
console.log(`- Created ${page.pl} / ${page.de}`);
|
||||
}
|
||||
|
||||
// Dodanie ich do globalnego nagłówka (pominąć 'Stowarzyszenie' i strony prawne jako główne menu wg życzenia)
|
||||
// "Domyślna zawartość na start: Strona główna / Usługi / Jak się umówić / O mnie / FAQ / Kontakt"
|
||||
console.log('Seeding global header...')
|
||||
|
||||
// @ts-ignore
|
||||
await payload.updateGlobal({
|
||||
slug: 'header',
|
||||
data: {
|
||||
navigation: pageIds.slice(0, 6).map(id => ({ page: id })),
|
||||
},
|
||||
});
|
||||
|
||||
console.log('Seeding global company info...')
|
||||
// @ts-ignore
|
||||
await payload.updateGlobal({
|
||||
slug: 'company',
|
||||
data: {
|
||||
address: 'Beratungsstelle b.b.h.\nLohnsteuerhilfeverein e.V.\nJanusz Kedzierski\nPrzykładowa ulica 123\n12345 Przykładowe Miasto',
|
||||
phone: '+49 123 456 789',
|
||||
email: '[email protected]',
|
||||
hours: 'Pon-Pt: 9:00 - 17:00\nPo wcześniejszym umówieniu',
|
||||
whatsappNumber: '49123456789',
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Seeding global footer...')
|
||||
// Wszystkie pozycje z headera + 3 strony prawne (Indeksy: od 0 do 5 oraz od 7 do 9)
|
||||
const footerNavIndices = [0, 1, 2, 3, 4, 5, 7, 8, 9];
|
||||
const footerNavPages = footerNavIndices.map(index => ({ page: pageIds[index] }));
|
||||
|
||||
// @ts-ignore
|
||||
await payload.updateGlobal({
|
||||
slug: 'footer',
|
||||
data: {
|
||||
navigation: footerNavPages,
|
||||
association: {
|
||||
title: 'Członek b.b.h. Lohnsteuerhilfeverein e.V.',
|
||||
link: 'https://bbh-lohnsteuerhilfe.de',
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Seeding site-settings (homepage)...')
|
||||
// @ts-ignore
|
||||
await payload.updateGlobal({
|
||||
slug: 'site-settings',
|
||||
data: {
|
||||
siteName: 'Janusz Kędzierski',
|
||||
titleOrder: 'page-first',
|
||||
titleSeparator: '|',
|
||||
homepage: pageIds[0], // Pierwsza strona to Strona główna (isHome: true)
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Seed completed.')
|
||||
} else {
|
||||
console.log('Pages already seeded.')
|
||||
}
|
||||
}
|
||||
|
||||
run().catch(console.error).finally(() => process.exit(0))
|
||||
Reference in New Issue
Block a user