diff --git a/src/app/(routes)/blog/page.tsx b/src/app/(routes)/blog/page.tsx index 578fcd9..7837a4a 100644 --- a/src/app/(routes)/blog/page.tsx +++ b/src/app/(routes)/blog/page.tsx @@ -21,6 +21,7 @@ export default async function BlogHomePage({ searchParams }: PageProps) { const recentArticleSlugs = await retrieveContentfulPublishedSlugs({ limit: 6, avoidTags: ["get-started"], + sortByRecent: true, }); const getStartedSlugs = await retrieveContentfulPublishedSlugs({ limit: 3, diff --git a/src/app/_lib/contentful.ts b/src/app/_lib/contentful.ts index f4aec90..6f81e85 100644 --- a/src/app/_lib/contentful.ts +++ b/src/app/_lib/contentful.ts @@ -50,11 +50,13 @@ export async function retrieveContentfulPublishedSlugs({ limit, avoidTags, includeTags, + sortByRecent, }: { query?: string; limit?: number; avoidTags?: string[]; includeTags?: string[]; + sortByRecent?: boolean; } = {}): Promise { const client = getProductionClient(); const options = { @@ -66,6 +68,7 @@ export async function retrieveContentfulPublishedSlugs({ ...(query ? { query } : {}), ...(avoidTags ? { "fields.tag[nin]": avoidTags.join(",").toLowerCase() } : {}), ...(includeTags ? { "fields.tag[in]": includeTags.join(",").toLowerCase() } : {}), + ...(sortByRecent ? { order: "-fields.publishDate" } : {}), } as const; const entries = await client.withoutUnresolvableLinks.getEntries(options); @@ -113,10 +116,8 @@ export async function retrieveRelevantContentfulEntries( "fields.tag[in]": tags.join(",").toLowerCase(), // get posts with same tags "fields.slug[nin]": entrySlugId, // don't include current post "fields.slug[exists]": true, // no empty slugs - - // TODO: Update existing posts to have publishDate - // "fields.publishDate[exists]": true, // no empty dates - // order: "-fields.publishDate", // sorted latest first + "fields.publishDate[exists]": true, // no empty dates + order: "-fields.publishDate", // sorted latest first } as const; const entries = await client.withoutUnresolvableLinks.getEntries(options);