Skip to content

Commit

Permalink
fix: use publish date field (#65)
Browse files Browse the repository at this point in the history
* fix: use publish date field

Signed-off-by: james-a-morris <[email protected]>

* nit: linting

Signed-off-by: james-a-morris <[email protected]>

---------

Signed-off-by: james-a-morris <[email protected]>
  • Loading branch information
james-a-morris authored Sep 17, 2024
1 parent 367758d commit cacb35a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/app/(routes)/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
resolvePublishDateToIsoDate,
retrieveContentfulEntry,
retrieveContentfulPublishedSlugs,
} from "@/app/_lib/contentful";
Expand Down Expand Up @@ -89,7 +90,6 @@ export default async function SpecificBlogPage({ params }: SpecificBlogPageProps
redirect("/404");
}
const fullTitle = entry.fields.title;
const dateCreatedAt = entry.sys.createdAt;
const content = entry.fields.content;
return (
<>
Expand All @@ -103,7 +103,10 @@ export default async function SpecificBlogPage({ params }: SpecificBlogPageProps
<Breadcrumb fullTitle={fullTitle} />
<ContentfulImage image={entry.fields.featuredImage} />
<SubStack className="text-center sm:text-left">
<MetaInfo isoCreatedDate={dateCreatedAt} content={content} />
<MetaInfo
isoCreatedDate={resolvePublishDateToIsoDate(entry)}
content={content}
/>
<h1 className="text-heading-3 font-lighter lining-nums tabular-nums tracking-tight-5 sm:text-heading-2">
{fullTitle}
</h1>
Expand Down
7 changes: 5 additions & 2 deletions src/app/(routes)/blog/_components/article-full-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { retrieveContentfulEntry } from "@/app/_lib/contentful";
import {
resolvePublishDateToIsoDate,
retrieveContentfulEntry,
} from "@/app/_lib/contentful";
import ContentfulImage from "../[slug]/_components/contentful-image";
import { MetaInfo } from "../[slug]/_components/meta-info";
import { documentToPlainTextString } from "@contentful/rich-text-plain-text-renderer";
Expand All @@ -20,7 +23,7 @@ export default async function ArticleFullCard({ slug }: { slug: string }) {
>
<div className="flex flex-col items-start justify-center gap-4">
<MetaInfo
isoCreatedDate={article.sys.createdAt}
isoCreatedDate={resolvePublishDateToIsoDate(article)}
content={article.fields.content}
/>
<Text variant="heading-4" className="line-clamp-2 group-hover:text-aqua-100">
Expand Down
4 changes: 2 additions & 2 deletions src/app/(routes)/blog/_components/article-snippet-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlogPostType } from "@/app/_lib/contentful";
import { BlogPostType, resolvePublishDateToIsoDate } from "@/app/_lib/contentful";
import { Text } from "@/app/_components/text";
import Link from "next/link";
import ContentfulImage from "../[slug]/_components/contentful-image";
Expand All @@ -18,7 +18,7 @@ export default function ArticleSnippetCard({
<ContentfulImage image={article.fields.featuredImage} borderless />
<div className="flex flex-col gap-4 p-5">
<MetaInfo
isoCreatedDate={article.sys.createdAt}
isoCreatedDate={resolvePublishDateToIsoDate(article)}
content={article.fields.content}
preventCenter
/>
Expand Down
4 changes: 4 additions & 0 deletions src/app/_lib/contentful.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ export function getReadingTime(content: Document): number {
const wordCount = words(rawText).length;
return Math.round(wordCount / averageReadingSpeed);
}

export function resolvePublishDateToIsoDate(entry: BlogPostType): string {
return entry.fields.publishDate ?? entry.sys.createdAt;
}

0 comments on commit cacb35a

Please sign in to comment.