Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use publish date field #65

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading