global values

This commit is contained in:
Tom Elliott 2025-04-12 13:27:41 +12:00
parent bb1d9a89df
commit 1ab9c10548
3 changed files with 128 additions and 2 deletions

View File

@ -84,8 +84,12 @@ export interface Config {
db: { db: {
defaultIDType: number; defaultIDType: number;
}; };
globals: {}; globals: {
globalsSelect: {}; home: Home;
};
globalsSelect: {
home: HomeSelect<false> | HomeSelect<true>;
};
locale: null; locale: null;
user: User & { user: User & {
collection: 'users'; collection: 'users';
@ -276,6 +280,74 @@ export interface PayloadMigrationsSelect<T extends boolean = true> {
updatedAt?: T; updatedAt?: T;
createdAt?: T; createdAt?: T;
} }
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "home".
*/
export interface Home {
id: number;
title?: string | null;
heroTitle?: string | null;
heroDescription?: {
root: {
type: string;
children: {
type: string;
version: number;
[k: string]: unknown;
}[];
direction: ('ltr' | 'rtl') | null;
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
indent: number;
version: number;
};
[k: string]: unknown;
} | null;
heroItems?:
| {
name: string;
id?: string | null;
}[]
| null;
projectsTitle?: string | null;
projectsDescription?: {
root: {
type: string;
children: {
type: string;
version: number;
[k: string]: unknown;
}[];
direction: ('ltr' | 'rtl') | null;
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
indent: number;
version: number;
};
[k: string]: unknown;
} | null;
updatedAt?: string | null;
createdAt?: string | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "home_select".
*/
export interface HomeSelect<T extends boolean = true> {
title?: T;
heroTitle?: T;
heroDescription?: T;
heroItems?:
| T
| {
name?: T;
id?: T;
};
projectsTitle?: T;
projectsDescription?: 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".

View File

@ -3,6 +3,7 @@ import { lexicalEditor } from '@payloadcms/richtext-lexical'
import { postgresAdapter } from '@payloadcms/db-postgres' import { postgresAdapter } from '@payloadcms/db-postgres'
import { buildConfig } from 'payload' import { buildConfig } from 'payload'
import { News } from './src/collections/News' import { News } from './src/collections/News'
import { Home } from '@/globals/Home'
export default buildConfig({ export default buildConfig({
// If you'd like to use Rich Text, pass your editor here // If you'd like to use Rich Text, pass your editor here
@ -10,6 +11,8 @@ export default buildConfig({
serverURL: process.env.SERVER_URL || 'http://localhost:3000', serverURL: process.env.SERVER_URL || 'http://localhost:3000',
globals: [Home],
// Define and configure your collections in this array // Define and configure your collections in this array
collections: [News], collections: [News],

51
src/globals/Home.ts Normal file
View File

@ -0,0 +1,51 @@
import { GlobalConfig } from "payload";
export const Home: GlobalConfig = {
slug: 'home',
fields: [
{
name: 'title',
label: 'Title',
type: 'text',
defaultValue: 'Analytics, research, and data visualisation that make a difference'
},
{
name: 'heroTitle',
label: 'Hero Title',
type: 'text',
defaultValue: 'We help people tell stories with data'
},
{
name: 'heroDescription',
label: 'Hero Description',
type: 'richText',
},
{
name: 'heroItems',
label: 'Hero Items',
type: 'array',
fields: [
{
name: 'name',
label: 'Name',
type: 'text',
required: true,
}
],
defaultValue: ["Data design", "Data collection", "Data analysis", "Data visualisation", "Training", "Data sovereignty"].map((item) => ({
name: item,
})),
},
{
name: 'projectsTitle',
label: 'Projects Title',
type: 'text',
defaultValue: 'We do data differently'
},
{
name: 'projectsDescription',
label: 'Projects Description',
type: 'richText'
}
],
};