Skip to content

Commit 9317299

Browse files
✨ feat: add optional books fields
1 parent ec09d6d commit 9317299

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

content/books/sample-book.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
title: "Clean Code"
33
authorName: "Robert C. Martin"
44
link: "https://www.oreilly.com/library/view/clean-code-a/9780136083238/"
5+
image: "https://m.media-amazon.com/images/I/41xShlnTZTL._SX374_BO1,204,203,200_.jpg"
6+
authorEmail: "unclebob@example.com"
7+
authorLink: "https://blog.cleancoder.com/"
58
---

contentlayer.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const bookFields: FieldDefs = {
5757
title: { type: "string", required: true },
5858
authorName: { type: "string", required: true },
5959
link: { type: "string", required: true },
60+
image: { type: "string", required: false },
61+
authorEmail: { type: "string", required: false },
62+
authorLink: { type: "string", required: false },
6063
};
6164

6265
export const Book = defineDocumentType(() => ({

src/app/books/page.tsx

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,45 @@ const BooksPage = async () => {
5555
className="rounded-3xl border border-white/10 bg-surface/50 p-6 transition-colors hover:border-white/20"
5656
>
5757
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
58-
<div>
59-
<h2 className="font-display text-2xl font-semibold text-zinc-100">
60-
{book.title}
61-
</h2>
62-
<p className="mt-2 text-sm text-zinc-400">
63-
by {book.authorName}
64-
</p>
58+
<div className="flex flex-col gap-4 sm:flex-row sm:items-start">
59+
{book.image && (
60+
<img
61+
src={book.image}
62+
alt={`${book.title} cover`}
63+
className="h-32 w-24 rounded-xl border border-white/10 object-cover"
64+
/>
65+
)}
66+
67+
<div>
68+
<h2 className="font-display text-2xl font-semibold text-zinc-100">
69+
{book.title}
70+
</h2>
71+
<p className="mt-2 text-sm text-zinc-400">
72+
by {book.authorName}
73+
</p>
74+
{(book.authorEmail || book.authorLink) && (
75+
<div className="mt-3 flex flex-col gap-2 text-sm">
76+
{book.authorEmail && (
77+
<a
78+
href={`mailto:${book.authorEmail}`}
79+
className="text-zinc-400 transition-colors hover:text-prism-cyan"
80+
>
81+
{book.authorEmail}
82+
</a>
83+
)}
84+
{book.authorLink && (
85+
<a
86+
href={book.authorLink}
87+
target="_blank"
88+
rel="noopener noreferrer"
89+
className="text-zinc-400 transition-colors hover:text-prism-cyan"
90+
>
91+
{book.authorLink}
92+
</a>
93+
)}
94+
</div>
95+
)}
96+
</div>
6597
</div>
6698

6799
<a

0 commit comments

Comments
 (0)