From 0823eff0ea3967aff8297302258398df50b6f18d Mon Sep 17 00:00:00 2001 From: Matthieu Bergel Date: Mon, 4 Mar 2024 14:30:35 +0000 Subject: [PATCH] enhance(latest work): exclude featured work --- db/model/Post.ts | 1 + .../types/src/domainTypes/Author.ts | 2 ++ site/gdocs/components/ResearchAndWriting.tsx | 20 ++++++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/db/model/Post.ts b/db/model/Post.ts index e996970796a..48b395a55d3 100644 --- a/db/model/Post.ts +++ b/db/model/Post.ts @@ -560,6 +560,7 @@ export const getLatestWorkByAuthor = async ( const rawLatestWorkLinks: DbRawLatestWork[] = await db.knexRaw( ` SELECT + pg.id, pg.slug, pg.content->>'$.title' AS title, pg.content->>'$.authors' AS authors, diff --git a/packages/@ourworldindata/types/src/domainTypes/Author.ts b/packages/@ourworldindata/types/src/domainTypes/Author.ts index 8d68da43f8f..3db6a878f9a 100644 --- a/packages/@ourworldindata/types/src/domainTypes/Author.ts +++ b/packages/@ourworldindata/types/src/domainTypes/Author.ts @@ -1,4 +1,5 @@ export interface DbRawLatestWork { + id: string slug: string title: string authors: string @@ -7,6 +8,7 @@ export interface DbRawLatestWork { } export interface DbEnrichedLatestWork { + id: string slug: string title: string authors: string[] diff --git a/site/gdocs/components/ResearchAndWriting.tsx b/site/gdocs/components/ResearchAndWriting.tsx index 9789a507037..574f3efb2d4 100644 --- a/site/gdocs/components/ResearchAndWriting.tsx +++ b/site/gdocs/components/ResearchAndWriting.tsx @@ -126,11 +126,25 @@ export function ResearchAndWriting(props: ResearchAndWritingProps) { const slug = heading ? slugify(heading) : RESEARCH_AND_WRITING_ID + // Get the URLs from the links of the featured work section. These will be + // excluded from the latest work section below to avoid duplication. + const primarySecondaryUrls = [...primary, ...secondary].map( + (link) => link.value.url + ) const { latestWorkLinks } = useContext(AttachmentsContext) if (latest && latestWorkLinks) { - latest.articles = latestWorkLinks.map( - parseLatestWorkToResearchAndWritingLink - ) + latest.articles = latestWorkLinks + // We want to filter out the primary and secondary links (aka. + // featured work links) from the latest work section to avoid + // duplication. Only featured links pointing to gdocs are + // considered. + .filter( + (link) => + !primarySecondaryUrls.includes( + `https://docs.google.com/document/d/${link.id}/edit` + ) + ) + .map(parseLatestWorkToResearchAndWritingLink) } return (