From 0afc27b02825c0bedd561cea5b83a0a0042f935f Mon Sep 17 00:00:00 2001 From: Benno Tielen Date: Wed, 20 Nov 2024 15:21:45 +0100 Subject: [PATCH] feature: blog --- src/app/(payload)/admin/importMap.js | 26 +-- src/app/blog/[id]/page.tsx | 69 +++++-- src/app/blog/[id]/styles.module.scss | 11 ++ src/app/globals.css | 6 + src/app/layout.tsx | 2 +- src/collections/Blog.ts | 53 ++--- src/collections/Documents.ts | 18 ++ src/collections/Media.ts | 29 ++- src/collections/blocks/Contactform.ts | 39 ++++ src/collections/blocks/Document.ts | 30 +++ src/collections/blocks/Paragraph.ts | 32 +++ src/components/Button/Button.tsx | 18 +- src/components/Button/styles.module.scss | 5 +- src/components/EventRow/styles.module.scss | 1 + .../HorizontalRule/styles.module.scss | 2 +- src/components/MassTable/styles.module.css | 3 +- src/components/RawHTML/RawHTML.tsx | 9 + src/components/Section/Section.tsx | 13 +- src/components/Section/styles.module.scss | 44 ++++- src/components/Text/HTMLText.tsx | 19 ++ src/components/Text/html.module.scss | 17 ++ .../ContactSection/ContactSection.tsx | 17 +- src/pageComponents/Home/Home.tsx | 1 - src/payload-types.ts | 182 +++++++++++++++--- src/payload.config.ts | 34 +++- 25 files changed, 563 insertions(+), 117 deletions(-) create mode 100644 src/app/blog/[id]/styles.module.scss create mode 100644 src/collections/Documents.ts create mode 100644 src/collections/blocks/Contactform.ts create mode 100644 src/collections/blocks/Document.ts create mode 100644 src/collections/blocks/Paragraph.ts create mode 100644 src/components/RawHTML/RawHTML.tsx create mode 100644 src/components/Text/HTMLText.tsx create mode 100644 src/components/Text/html.module.scss diff --git a/src/app/(payload)/admin/importMap.js b/src/app/(payload)/admin/importMap.js index dfe0789..bf0b4f9 100644 --- a/src/app/(payload)/admin/importMap.js +++ b/src/app/(payload)/admin/importMap.js @@ -1,22 +1,11 @@ import { RscEntryLexicalCell as RscEntryLexicalCell_44fe37237e0ebf4470c9990d8cb7b07e } from '@payloadcms/richtext-lexical/rsc' import { RscEntryLexicalField as RscEntryLexicalField_44fe37237e0ebf4470c9990d8cb7b07e } from '@payloadcms/richtext-lexical/rsc' import { InlineToolbarFeatureClient as InlineToolbarFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { HorizontalRuleFeatureClient as HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { UploadFeatureClient as UploadFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { BlockquoteFeatureClient as BlockquoteFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { RelationshipFeatureClient as RelationshipFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' +import { ParagraphFeatureClient as ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' import { LinkFeatureClient as LinkFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { ChecklistFeatureClient as ChecklistFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { OrderedListFeatureClient as OrderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' import { UnorderedListFeatureClient as UnorderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { IndentFeatureClient as IndentFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' import { AlignFeatureClient as AlignFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' import { HeadingFeatureClient as HeadingFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { ParagraphFeatureClient as ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { InlineCodeFeatureClient as InlineCodeFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { SuperscriptFeatureClient as SuperscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { SubscriptFeatureClient as SubscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' -import { StrikethroughFeatureClient as StrikethroughFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' import { UnderlineFeatureClient as UnderlineFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' import { BoldFeatureClient as BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' import { ItalicFeatureClient as ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client' @@ -25,22 +14,11 @@ export const importMap = { "@payloadcms/richtext-lexical/rsc#RscEntryLexicalCell": RscEntryLexicalCell_44fe37237e0ebf4470c9990d8cb7b07e, "@payloadcms/richtext-lexical/rsc#RscEntryLexicalField": RscEntryLexicalField_44fe37237e0ebf4470c9990d8cb7b07e, "@payloadcms/richtext-lexical/client#InlineToolbarFeatureClient": InlineToolbarFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#HorizontalRuleFeatureClient": HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#UploadFeatureClient": UploadFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#BlockquoteFeatureClient": BlockquoteFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#RelationshipFeatureClient": RelationshipFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, + "@payloadcms/richtext-lexical/client#ParagraphFeatureClient": ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, "@payloadcms/richtext-lexical/client#LinkFeatureClient": LinkFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#ChecklistFeatureClient": ChecklistFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#OrderedListFeatureClient": OrderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, "@payloadcms/richtext-lexical/client#UnorderedListFeatureClient": UnorderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#IndentFeatureClient": IndentFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, "@payloadcms/richtext-lexical/client#AlignFeatureClient": AlignFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, "@payloadcms/richtext-lexical/client#HeadingFeatureClient": HeadingFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#ParagraphFeatureClient": ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#InlineCodeFeatureClient": InlineCodeFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#SuperscriptFeatureClient": SuperscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#SubscriptFeatureClient": SubscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, - "@payloadcms/richtext-lexical/client#StrikethroughFeatureClient": StrikethroughFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, "@payloadcms/richtext-lexical/client#UnderlineFeatureClient": UnderlineFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, "@payloadcms/richtext-lexical/client#BoldFeatureClient": BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864, "@payloadcms/richtext-lexical/client#ItalicFeatureClient": ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 diff --git a/src/app/blog/[id]/page.tsx b/src/app/blog/[id]/page.tsx index 9e9aa16..b2f3bb9 100644 --- a/src/app/blog/[id]/page.tsx +++ b/src/app/blog/[id]/page.tsx @@ -1,10 +1,16 @@ import { Section } from '@/components/Section/Section' import { Container } from '@/components/Container/Container' import { Title } from '@/components/Title/Title' -import { ContentWithSlider } from '@/compositions/ContentWithSlider/ContentWithSlider' import { TextDiv } from '@/components/Text/TextDiv' import { Blog } from '@/payload-types' import { notFound } from 'next/navigation' +import { readableDateTime } from '@/utils/readableDate' +import { HR } from '@/components/HorizontalRule/HorizontalRule' +import Image from 'next/image' +import styles from "./styles.module.scss" +import { HTMLText } from '@/components/Text/HTMLText' +import { Button } from '@/components/Button/Button' +import { ContactSection } from '@/compositions/ContactSection/ContactSection' async function fetchBlog(id: string) { const res = await fetch(`http://localhost:3000/api/blog/${id}`) @@ -16,30 +22,67 @@ export default async function BlogPage({ params }: { params: Promise<{id: string const id = (await params).id; const data = await fetchBlog(id) as Blog; + const url = typeof data.photo === 'object' && data.photo?.sizes?.banner?.url; if(!data) { notFound(); } + // determine if some margin at the bottom should be added + const length = data.content.length; + const shouldAddMargin = data.content[length - 1].blockType === "text" + return ( -
- - - + <> +
+ + + +

+ Publiziert am {readableDateTime(data.createdAt)} +

+
+
+ +
+ { typeof url === "string" && + {""} + } +
+
+
+
- {data.content && data.content.map(item => { - if (item.blockType === "ContentWithSlider") { + {data.content.map(item => { + if (item.blockType === "text" && item.content_html) { return ( - - - - - + + + ); } + if (item.blockType === "document" && typeof item.file === "object") { + return ( + +
+ +
+
+ ) + } + + if (item.blockType === "contactform") { + return ( + + ) + } })}
-
+ + { shouldAddMargin && +
+ } + ) } \ No newline at end of file diff --git a/src/app/blog/[id]/styles.module.scss b/src/app/blog/[id]/styles.module.scss new file mode 100644 index 0000000..3b17b46 --- /dev/null +++ b/src/app/blog/[id]/styles.module.scss @@ -0,0 +1,11 @@ +@import "template.scss"; + +.image { + max-width: 100%; + height: auto; + border-radius: $border-radius; +} + +.published { + font-size: 12px; +} \ No newline at end of file diff --git a/src/app/globals.css b/src/app/globals.css index 02109cc..94846a9 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -4,8 +4,14 @@ body { display: flex; flex-direction: column; min-height: 100vh; + color: #2c2c2c; } main { flex: 1; } + +.mainContent { + font-size: 20px; + line-height: 147%; +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 266eae1..9b3c770 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -17,7 +17,7 @@ export default function RootLayout({ -
+
{children}