From 691729c53c8ebd1e6f3c1bb89c875c5355421a2d Mon Sep 17 00:00:00 2001 From: tobias Date: Tue, 21 May 2024 11:17:40 +0200 Subject: [PATCH] Create author component --- astro/src/components/Author.astro | 27 +++++++++++++++++++++++++++ astro/src/pages/posts/[id].astro | 9 +++++++-- payload/src/collections/Authors.ts | 17 +++++++++++------ 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 astro/src/components/Author.astro diff --git a/astro/src/components/Author.astro b/astro/src/components/Author.astro new file mode 100644 index 0000000..8e72f66 --- /dev/null +++ b/astro/src/components/Author.astro @@ -0,0 +1,27 @@ +--- +import { Image } from "@astrojs/image/components"; +import type { Author } from "@/types/payload-types"; + +interface Props { + author: Author; +} + +const { author } = Astro.props; +--- +{ (author) && +
+ {(typeof author.avatar === 'object') && + {author.avatar.alt + } +
+

{author.name}

+

{author.bio}

+
+
+} \ No newline at end of file diff --git a/astro/src/pages/posts/[id].astro b/astro/src/pages/posts/[id].astro index 8e65a1d..f82f93e 100644 --- a/astro/src/pages/posts/[id].astro +++ b/astro/src/pages/posts/[id].astro @@ -1,8 +1,9 @@ --- import ContentLayout from "@/layouts/ContentLayout.astro"; import Content from "@/components/Content.astro"; -import type { Post } from "@/types"; +import type { Post } from "@/types/payload-types"; import { getPost, getPosts } from "@/utils/payload"; +import Author from "@/components/Author.astro"; export async function getStaticPaths() { const posts = await getPosts(); @@ -18,11 +19,15 @@ const post = id && (await getPost(id)); { post ? ( - +

{post.title}

{post.content && }
+ {typeof post.author === 'object' && + }
) : (
404
diff --git a/payload/src/collections/Authors.ts b/payload/src/collections/Authors.ts index a09e2f8..52253b6 100644 --- a/payload/src/collections/Authors.ts +++ b/payload/src/collections/Authors.ts @@ -3,12 +3,11 @@ import { isAdmin } from "@/access/isAdmin"; import { isEditor } from "@/access/isEditor"; import { isSSG } from "@/access/isSSG"; import { isUser } from "@/access/isUser"; -import { isEditorOrSelf } from "@/access/isEditorOrSelf"; const Authors: CollectionConfig = { slug: "authors", admin: { - defaultColumns: ["avatar","name"], + defaultColumns: ["name"], useAsTitle: "name", }, access: { @@ -19,20 +18,26 @@ const Authors: CollectionConfig = { delete: isEditor, }, fields: [ + { + name: "avatar", + type: "upload", + relationTo: "media", + required: true, + }, { name: "name", type: "text", required: true }, { - name: "avatar", - type: "upload", - relationTo: "media", + name: "bio", + type: "text", required: false, }, + { name: "user", - type: "relationship", + type: "upload", relationTo: "users", admin: { description: 'The selected user will be able to edit this author'