feat: add site-config
This commit is contained in:
parent
4c21073001
commit
e32ff73233
6 changed files with 222 additions and 18 deletions
|
|
@ -6,23 +6,41 @@ import { comment } from '@/app/(home)/layout-comment'
|
||||||
import { FONT_MAP, getFont } from '@/assets/fonts'
|
import { FONT_MAP, getFont } from '@/assets/fonts'
|
||||||
import { siteConfig } from '@/config/site'
|
import { siteConfig } from '@/config/site'
|
||||||
import { fetchDesign } from '@/fetch/design'
|
import { fetchDesign } from '@/fetch/design'
|
||||||
|
import { fetchSiteConfig } from '@/fetch/siteConfig'
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export async function generateMetadata(): Promise<Metadata> {
|
||||||
|
let site
|
||||||
|
try {
|
||||||
|
site = await fetchSiteConfig()
|
||||||
|
} catch {
|
||||||
|
site = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = site?.name || siteConfig.name
|
||||||
|
const shortName = site?.shortName || siteConfig.shortName
|
||||||
|
const description = site?.description || siteConfig.description
|
||||||
|
const url = site?.url || siteConfig.url
|
||||||
|
const ogImage = site?.ogImage || siteConfig.ogImage
|
||||||
|
const keywords =
|
||||||
|
site?.keywords?.map((k) => k.keyword) || siteConfig.keywords
|
||||||
|
|
||||||
|
return {
|
||||||
title: {
|
title: {
|
||||||
default: siteConfig.name,
|
default: name,
|
||||||
template: `%s | ${siteConfig.shortName}`,
|
template: `%s | ${shortName}`,
|
||||||
},
|
},
|
||||||
description: siteConfig.description,
|
description,
|
||||||
keywords: siteConfig.keywords,
|
keywords,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title: siteConfig.name,
|
title: name,
|
||||||
description: siteConfig.description,
|
description,
|
||||||
url: siteConfig.url,
|
url,
|
||||||
siteName: siteConfig.name,
|
siteName: name,
|
||||||
images: [siteConfig.ogImage],
|
images: [ogImage],
|
||||||
locale: 'de_DE',
|
locale: 'de_DE',
|
||||||
type: 'website',
|
type: 'website',
|
||||||
},
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DESIGN_DEFAULTS = {
|
const DESIGN_DEFAULTS = {
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,13 @@ export const ContactformBlock: Block = {
|
||||||
{
|
{
|
||||||
name: 'email',
|
name: 'email',
|
||||||
type: 'email',
|
type: 'email',
|
||||||
defaultValue: siteConfig.email,
|
defaultValue: async ({ req }) => {
|
||||||
required: true
|
const config = await req.payload.findGlobal({
|
||||||
|
slug: 'site-config',
|
||||||
|
})
|
||||||
|
return config?.email || siteConfig.email
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
16
src/fetch/siteConfig.ts
Normal file
16
src/fetch/siteConfig.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { SiteConfig } from '@/payload-types'
|
||||||
|
|
||||||
|
export async function fetchSiteConfig(): Promise<SiteConfig> {
|
||||||
|
const res = await fetch(
|
||||||
|
'http://localhost:3000/api/globals/site-config',
|
||||||
|
{
|
||||||
|
next: { tags: ['site-config'] },
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error('Could not fetch site-config')
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json()
|
||||||
|
}
|
||||||
102
src/globals/SiteConfig.ts
Normal file
102
src/globals/SiteConfig.ts
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
import { GlobalConfig } from 'payload'
|
||||||
|
import { isAdmin } from '@/collections/access/admin'
|
||||||
|
import { revalidateTag } from 'next/cache'
|
||||||
|
|
||||||
|
export const SiteConfigGlobal: GlobalConfig = {
|
||||||
|
slug: 'site-config',
|
||||||
|
label: {
|
||||||
|
de: 'Website-Einstellungen',
|
||||||
|
},
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
'Hier können Sie den Namen, die Beschreibung und andere allgemeine Einstellungen der Website konfigurieren.',
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
type: 'text',
|
||||||
|
label: { de: 'Name der Pfarrei' },
|
||||||
|
required: true,
|
||||||
|
defaultValue:
|
||||||
|
'Katholische Pfarrei Heilige Drei Könige Berlin',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'shortName',
|
||||||
|
type: 'text',
|
||||||
|
label: { de: 'Kurzname' },
|
||||||
|
required: true,
|
||||||
|
defaultValue: 'Hl. Drei Könige',
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
'Wird im Browser-Tab als Suffix verwendet (z.B. "Seite | Hl. Drei Könige").',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'description',
|
||||||
|
type: 'textarea',
|
||||||
|
label: { de: 'Beschreibung' },
|
||||||
|
required: true,
|
||||||
|
defaultValue:
|
||||||
|
'Katholische Pfarrei Heilige Drei Könige in Berlin – Gottesdienste, Veranstaltungen, Sakramente und Gemeindeleben.',
|
||||||
|
admin: {
|
||||||
|
description: 'Meta-Beschreibung für Suchmaschinen.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'url',
|
||||||
|
type: 'text',
|
||||||
|
label: { de: 'Website-URL' },
|
||||||
|
required: true,
|
||||||
|
defaultValue: 'https://dreikoenige.berlin',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ogImage',
|
||||||
|
type: 'text',
|
||||||
|
label: { de: 'Open Graph Bild' },
|
||||||
|
defaultValue: '/og-logo.svg',
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
'Pfad zum Vorschaubild für soziale Medien.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'email',
|
||||||
|
type: 'email',
|
||||||
|
label: { de: 'Kontakt-E-Mail' },
|
||||||
|
required: true,
|
||||||
|
defaultValue: 'kontakt@dreikoenige.berlin',
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
'Standard-E-Mail-Adresse für Kontaktformulare.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'keywords',
|
||||||
|
type: 'array',
|
||||||
|
label: { de: 'Schlüsselwörter' },
|
||||||
|
labels: {
|
||||||
|
singular: { de: 'Schlüsselwort' },
|
||||||
|
plural: { de: 'Schlüsselwörter' },
|
||||||
|
},
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
'SEO-Schlüsselwörter für Suchmaschinen.',
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'keyword',
|
||||||
|
type: 'text',
|
||||||
|
required: true,
|
||||||
|
label: { de: 'Schlüsselwort' },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
access: {
|
||||||
|
read: () => true,
|
||||||
|
update: isAdmin(),
|
||||||
|
},
|
||||||
|
hooks: {
|
||||||
|
afterChange: [() => revalidateTag('site-config')],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -127,11 +127,13 @@ export interface Config {
|
||||||
menu: Menu;
|
menu: Menu;
|
||||||
footer: Footer;
|
footer: Footer;
|
||||||
design: Design;
|
design: Design;
|
||||||
|
'site-config': SiteConfig;
|
||||||
};
|
};
|
||||||
globalsSelect: {
|
globalsSelect: {
|
||||||
menu: MenuSelect<false> | MenuSelect<true>;
|
menu: MenuSelect<false> | MenuSelect<true>;
|
||||||
footer: FooterSelect<false> | FooterSelect<true>;
|
footer: FooterSelect<false> | FooterSelect<true>;
|
||||||
design: DesignSelect<false> | DesignSelect<true>;
|
design: DesignSelect<false> | DesignSelect<true>;
|
||||||
|
'site-config': SiteConfigSelect<false> | SiteConfigSelect<true>;
|
||||||
};
|
};
|
||||||
locale: null;
|
locale: null;
|
||||||
user: User & {
|
user: User & {
|
||||||
|
|
@ -1956,6 +1958,44 @@ export interface Design {
|
||||||
updatedAt?: string | null;
|
updatedAt?: string | null;
|
||||||
createdAt?: string | null;
|
createdAt?: string | null;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Hier können Sie den Namen, die Beschreibung und andere allgemeine Einstellungen der Website konfigurieren.
|
||||||
|
*
|
||||||
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
|
* via the `definition` "site-config".
|
||||||
|
*/
|
||||||
|
export interface SiteConfig {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
/**
|
||||||
|
* Wird im Browser-Tab als Suffix verwendet (z.B. "Seite | Hl. Drei Könige").
|
||||||
|
*/
|
||||||
|
shortName: string;
|
||||||
|
/**
|
||||||
|
* Meta-Beschreibung für Suchmaschinen.
|
||||||
|
*/
|
||||||
|
description: string;
|
||||||
|
url: string;
|
||||||
|
/**
|
||||||
|
* Pfad zum Vorschaubild für soziale Medien.
|
||||||
|
*/
|
||||||
|
ogImage?: string | null;
|
||||||
|
/**
|
||||||
|
* Standard-E-Mail-Adresse für Kontaktformulare.
|
||||||
|
*/
|
||||||
|
email: string;
|
||||||
|
/**
|
||||||
|
* SEO-Schlüsselwörter für Suchmaschinen.
|
||||||
|
*/
|
||||||
|
keywords?:
|
||||||
|
| {
|
||||||
|
keyword: string;
|
||||||
|
id?: string | null;
|
||||||
|
}[]
|
||||||
|
| null;
|
||||||
|
updatedAt?: string | null;
|
||||||
|
createdAt?: string | null;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `Config`'s JSON-Schema
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
* via the `definition` "menu_select".
|
* via the `definition` "menu_select".
|
||||||
|
|
@ -2077,6 +2117,27 @@ export interface DesignSelect<T extends boolean = true> {
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
globalType?: T;
|
globalType?: T;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
|
* via the `definition` "site-config_select".
|
||||||
|
*/
|
||||||
|
export interface SiteConfigSelect<T extends boolean = true> {
|
||||||
|
name?: T;
|
||||||
|
shortName?: T;
|
||||||
|
description?: T;
|
||||||
|
url?: T;
|
||||||
|
ogImage?: T;
|
||||||
|
email?: T;
|
||||||
|
keywords?:
|
||||||
|
| T
|
||||||
|
| {
|
||||||
|
keyword?: T;
|
||||||
|
id?: T;
|
||||||
|
};
|
||||||
|
updatedAt?: T;
|
||||||
|
createdAt?: T;
|
||||||
|
globalType?: T;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `Config`'s JSON-Schema
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
* via the `definition` "auth".
|
* via the `definition` "auth".
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import { Classifieds } from '@/collections/Classifieds'
|
||||||
import { MenuGlobal } from '@/globals/Menu'
|
import { MenuGlobal } from '@/globals/Menu'
|
||||||
import { FooterGlobal } from '@/globals/Footer'
|
import { FooterGlobal } from '@/globals/Footer'
|
||||||
import { DesignGlobal } from '@/globals/Design'
|
import { DesignGlobal } from '@/globals/Design'
|
||||||
|
import { SiteConfigGlobal } from '@/globals/SiteConfig'
|
||||||
import { Magazine } from '@/collections/Magazine'
|
import { Magazine } from '@/collections/Magazine'
|
||||||
import { DonationForms } from '@/collections/DonationForms'
|
import { DonationForms } from '@/collections/DonationForms'
|
||||||
import { Pages } from '@/collections/Pages'
|
import { Pages } from '@/collections/Pages'
|
||||||
|
|
@ -107,6 +108,7 @@ export default buildConfig({
|
||||||
MenuGlobal,
|
MenuGlobal,
|
||||||
FooterGlobal,
|
FooterGlobal,
|
||||||
DesignGlobal,
|
DesignGlobal,
|
||||||
|
SiteConfigGlobal,
|
||||||
],
|
],
|
||||||
graphQL: {
|
graphQL: {
|
||||||
disable: true
|
disable: true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue