11---
22import type { CollectionEntry } from ' astro:content' ;
3+ import { getCollection } from ' astro:content' ;
34import BaseHead from ' ../components/BaseHead.astro' ;
45import Header from ' ../components/Header.astro' ;
56import Footer from ' ../components/Footer.astro' ;
67import FormattedDate from ' ../components/FormattedDate.astro' ;
78
89type Props = CollectionEntry <' blog' >[' data' ];
910
10- const { title, description, pubDate, updatedDate, heroImage } = Astro .props ;
11+ const { title, description, pubDate, updatedDate, heroImage, authors } = Astro .props ;
12+
13+ // Get author information if authors are specified
14+ let authorData: CollectionEntry <' authors' >[] = [];
15+ if (authors && authors .length > 0 ) {
16+ const allAuthors = await getCollection (' authors' );
17+ authorData = allAuthors .filter (author => authors .includes (author .id ));
18+ }
1119---
1220
1321<html lang =" en" >
@@ -51,6 +59,37 @@ const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
5159 .last-updated-on {
5260 font-style: italic;
5361 }
62+ .authors {
63+ margin: 1em 0;
64+ display: flex;
65+ flex-wrap: wrap;
66+ justify-content: center;
67+ gap: 1rem;
68+ }
69+ .author {
70+ display: flex;
71+ align-items: center;
72+ gap: 0.5rem;
73+ padding: 0.5rem;
74+ border-radius: 8px;
75+ background: rgba(var(--accent-light), 0.1);
76+ text-decoration: none;
77+ color: inherit;
78+ transition: background-color 0.2s ease;
79+ }
80+ .author:hover {
81+ background: rgba(var(--accent-light), 0.2);
82+ }
83+ .author-avatar {
84+ width: 32px;
85+ height: 32px;
86+ border-radius: 50%;
87+ object-fit: cover;
88+ }
89+ .author-name {
90+ font-weight: 500;
91+ color: rgb(var(--black));
92+ }
5493 </style >
5594 </head >
5695
@@ -74,6 +113,22 @@ const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
74113 }
75114 </div >
76115 <h1 >{ title } </h1 >
116+ { authorData .length > 0 && (
117+ <div class = " authors" >
118+ { authorData .map ((author ) => (
119+ <a href = { ` ${import .meta .env .BASE_URL }/authors/${author .id }/ ` } class = " author" >
120+ { author .data .avatar && (
121+ <img
122+ src = { author .data .avatar .startsWith (' /' ) ? ` ${import .meta .env .BASE_URL }/${author .data .avatar .slice (1 )} ` : author .data .avatar }
123+ alt = { author .data .name }
124+ class = " author-avatar"
125+ />
126+ )}
127+ <span class = " author-name" >{ author .data .name } </span >
128+ </a >
129+ ))}
130+ </div >
131+ )}
77132 <hr />
78133 </div >
79134 <slot />
0 commit comments