Skip to content

Commit ea2e572

Browse files
committed
fix: ensure articles are filtered by publish status and improve error handling in author data retrieval
1 parent c3860e1 commit ea2e572

2 files changed

Lines changed: 32 additions & 15 deletions

File tree

app/posts/[title]/page.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface Article {
3232
content: string;
3333
date: Date;
3434
read: string;
35+
publish: boolean;
3536
label: string;
3637
img: string;
3738
imgAlt: string;
@@ -115,11 +116,17 @@ export default async function ArticleDetails({
115116
authorUID: articleData.authorUID,
116117
authorName: authorData.name || "Unknown Author",
117118
authorAvatar: authorData.avatar || "/default-avatar.png",
119+
publish: false
118120
};
119121

120122
// Get latest articles (excluding current)
121123
const latestSnapshot = await getDocs(
122-
query(collection(db, "articles"), orderBy("date", "desc"), limit(4))
124+
query(
125+
collection(db, "articles"),
126+
where("publish", "==", true),
127+
orderBy("date", "desc"),
128+
limit(4)
129+
)
123130
);
124131

125132
const latestArticles = latestSnapshot.docs
@@ -188,7 +195,7 @@ export default async function ArticleDetails({
188195
<div className="w">
189196
<ArticleContent content={processedArticle.content} />
190197
</div>
191-
198+
192199
<div className="pt-10 pb-20">
193200
<Subheading
194201
className="text-subheading"

app/team/[author]/page.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ async function getAuthorData(slug: string) {
6969
})) as ArticleData[];
7070

7171
return { author: authorData, articles };
72-
}
73-
// Fallback approach if composite index isn't available
74-
catch (error) {
72+
} catch (error) {
73+
// Fallback approach if composite index isn't available
7574
console.log("Using fallback approach for querying articles:", error);
7675

7776
// First get all articles by this author
@@ -89,13 +88,16 @@ async function getAuthorData(slug: string) {
8988
return {
9089
uid: doc.id,
9190
...data,
92-
date: data.date && typeof data.date.toDate === 'function'
93-
? data.date.toDate()
94-
: (data.date instanceof Date ? data.date : new Date()),
95-
publish: data.publish ?? false
91+
date:
92+
data.date && typeof data.date.toDate === "function"
93+
? data.date.toDate()
94+
: data.date instanceof Date
95+
? data.date
96+
: new Date(),
97+
publish: data.publish ?? false,
9698
} as ArticleData;
9799
})
98-
.filter(article => article.publish === true);
100+
.filter((article) => article.publish === true);
99101

100102
return { author: authorData, articles };
101103
}
@@ -120,7 +122,11 @@ const SOCIAL_ICONS: { [key: string]: any } = {
120122
};
121123

122124
// **Async page component**
123-
export default async function Page({ params }: { params: Promise<{ author: string }> }) {
125+
export default async function Page({
126+
params,
127+
}: {
128+
params: Promise<{ author: string }>;
129+
}) {
124130
const { author } = await params; // Await the params object
125131
const data = await getAuthorData(author);
126132

@@ -137,7 +143,7 @@ export default async function Page({ params }: { params: Promise<{ author: strin
137143
.map(([platform, url]) => ({
138144
href: url,
139145
ariaLabel: `Visit ${authorData.name}'s ${platform} page`,
140-
Icon: SOCIAL_ICONS[platform.toLowerCase()] || RiGithubFill, // Default to GitHub icon if unknown
146+
Icon: SOCIAL_ICONS[platform.toLowerCase()] || RiGithubFill,
141147
}))
142148
: [];
143149

@@ -164,7 +170,9 @@ export default async function Page({ params }: { params: Promise<{ author: strin
164170
{/* **Author Biography** */}
165171
<article>
166172
<h1 className="text-subheading pb-8">{authorData.name}</h1>
167-
<p className="text-blog-summary pb-12">{authorData.biography.summary}</p>
173+
<p className="text-blog-summary pb-12">
174+
{authorData.biography.summary}
175+
</p>
168176
<p className="text-blog-body">{authorData.biography.body}</p>
169177
</article>
170178
</article>
@@ -211,7 +219,10 @@ function AuthorArticles({ articles }: { articles: ArticleData[] }) {
211219
</Link>
212220
<div>
213221
<p className="heading3-title pb-2 sm:pb-4">
214-
<Link href={`/posts/${article.slug}`} className="hover:text-white transition-colors">
222+
<Link
223+
href={`/posts/${article.slug}`}
224+
className="hover:text-white transition-colors"
225+
>
215226
{article.title}
216227
</Link>
217228
</p>
@@ -240,4 +251,3 @@ function AuthorArticles({ articles }: { articles: ArticleData[] }) {
240251
</div>
241252
);
242253
}
243-

0 commit comments

Comments
 (0)