Skip to content

Commit

Permalink
Fix pluralization of 'N comments' on LinkCard and Post layout
Browse files Browse the repository at this point in the history
Also deleted vestigial getCommentCount
  • Loading branch information
tylermercer committed Mar 4, 2025
1 parent b261d19 commit 3366fc6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
16 changes: 16 additions & 0 deletions src/components/CommentsCount.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
import getCommentCount from "lib/utils/getJamCommentsCommentCount";
export interface Props {
pathname?: string;
}
const commentCount = getCommentCount(Astro.props.pathname ?? Astro.url.pathname);
---
{
commentCount > 0
? commentCount === 1
? "1 comment"
: `${commentCount} comments`
: "No comments yet"
}
6 changes: 2 additions & 4 deletions src/components/LinkCard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getLinkDate from "@utils/getLinkDate";
import type { CollectionEntry } from "astro:content";
import formatPostDate from "../utils/formatPostDate";
import getLinkSlug from "@utils/getLinkSlug";
import getCommentCount from "lib/utils/getJamCommentsCommentCount";
import CommentsCount from "./CommentsCount.astro";
export type Props = {
link: CollectionEntry<"links">;
Expand Down Expand Up @@ -33,9 +33,7 @@ const permalink = `/links/${getLinkSlug(l)}`;
{formatPostDate(getLinkDate(l.slug))}
</time>
</a> &middot;{" "}
<a href={permalink + "#comments"}>
{getCommentCount(permalink)} comments
</a>
<a href={permalink + "#comments"}><CommentsCount pathname={permalink} /></a>
</p>
</article>

Expand Down
6 changes: 3 additions & 3 deletions src/layouts/Post.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import countWords from "@utils/countWords";
import formatPostDate from "@utils/formatPostDate";
import getPostDate from "@utils/getPostDate";
import type { WithNextAndPrev } from "lib/utils/toWithNextAndPrev";
import getCommentCount from "@utils/getCommentCount";
import CommentsCount from "@components/CommentsCount.astro";
export type Props = {
post: WithNextAndPrev<CollectionEntry<"posts">>;
Expand Down Expand Up @@ -68,15 +68,15 @@ const ogImagePath = `/posts/${post.slug}`;
}
<span> &mdash;</span>
{wordCount} words &mdash; {readingTime} min read{" "}
<span> &mdash; <a href="#comments">{getCommentCount(Astro.url.pathname)} comments</a></span>
<span> &mdash; <a href="#comments"><CommentsCount /></a></span>
</p>
<div class:list={{ "article-content": true, "drop-caps": dropCaps }}>
<slot />
<!-- <div class="reply-and-share">
<MungedEmail label="Reply via email" subject={post.data.title} />
<ShareLinks url={url} title={post.data.title} />
</div> -->
<Comments/>
<Comments />
</div>
</div>
<NextPrevLinks previous={previousLink} next={nextLink} labelLinks />
Expand Down
26 changes: 0 additions & 26 deletions src/utils/getCommentCount.ts

This file was deleted.

0 comments on commit 3366fc6

Please sign in to comment.