Compare commits

...

1 Commits

Author SHA1 Message Date
German Jablonski
a44857a2ee cannot reproduce in website template 2025-08-22 15:41:28 +01:00
5 changed files with 41 additions and 2 deletions

View File

@@ -47,6 +47,8 @@ export default async function Post({ params: paramsPromise }: Args) {
const url = '/posts/' + slug
const post = await queryPostBySlug({ slug })
console.log('post', post)
if (!post) return <PayloadRedirects url={url} />
return (
@@ -91,6 +93,7 @@ const queryPostBySlug = cache(async ({ slug }: { slug: string }) => {
collection: 'posts',
draft,
limit: 1,
// depth: 0, // IF YOU UNCOMMENT THIS, THE BLOCKS WILL NOT BE POPULATED
overrideAccess: draft,
pagination: false,
where: {

View File

@@ -0,0 +1,13 @@
import type { Block } from 'payload'
export const RelationshipBlock: Block = {
slug: 'relationshipBlock',
interfaceName: 'RelationshipBlock',
fields: [
{
name: 'relationship',
type: 'relationship',
relationTo: 'posts',
},
],
}

View File

@@ -26,6 +26,7 @@ import {
PreviewField,
} from '@payloadcms/plugin-seo/fields'
import { slugField } from '@/fields/slug'
import { RelationshipBlock } from '@/blocks/Relationship/config'
export const Posts: CollectionConfig<'posts'> = {
slug: 'posts',
@@ -92,7 +93,9 @@ export const Posts: CollectionConfig<'posts'> = {
return [
...rootFeatures,
HeadingFeature({ enabledHeadingSizes: ['h1', 'h2', 'h3', 'h4'] }),
BlocksFeature({ blocks: [Banner, Code, MediaBlock] }),
BlocksFeature({
blocks: [Banner, Code, MediaBlock, RelationshipBlock],
}),
FixedToolbarFeature(),
InlineToolbarFeature(),
HorizontalRuleFeature(),

View File

@@ -17,6 +17,7 @@ import type {
BannerBlock as BannerBlockProps,
CallToActionBlock as CTABlockProps,
MediaBlock as MediaBlockProps,
RelationshipBlock,
} from '@/payload-types'
import { BannerBlock } from '@/blocks/Banner/Component'
import { CallToActionBlock } from '@/blocks/CallToAction/Component'
@@ -24,7 +25,9 @@ import { cn } from '@/utilities/ui'
type NodeTypes =
| DefaultNodeTypes
| SerializedBlockNode<CTABlockProps | MediaBlockProps | BannerBlockProps | CodeBlockProps>
| SerializedBlockNode<
CTABlockProps | MediaBlockProps | BannerBlockProps | CodeBlockProps | RelationshipBlock
>
const internalDocToHref = ({ linkNode }: { linkNode: SerializedLinkNode }) => {
const { value, relationTo } = linkNode.fields.doc!
@@ -52,6 +55,13 @@ const jsxConverters: JSXConvertersFunction<NodeTypes> = ({ defaultConverters })
),
code: ({ node }) => <CodeBlock className="col-start-2" {...node.fields} />,
cta: ({ node }) => <CallToActionBlock {...node.fields} />,
relationshipBlock: ({ node }) => {
console.log('relationshipBlock', node)
const relationship = node.fields.relationship
if (typeof relationship !== 'object')
return <pre>{JSON.stringify(relationship, null, 2)}</pre>
return <pre>{JSON.stringify(relationship?.title, null, 2)}</pre>
},
},
})

View File

@@ -1708,6 +1708,16 @@ export interface CodeBlock {
blockName?: string | null;
blockType: 'code';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "RelationshipBlock".
*/
export interface RelationshipBlock {
relationship?: (string | null) | Post;
id?: string | null;
blockName?: string | null;
blockType: 'relationshipBlock';
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "auth".