Skip to content

Commit

Permalink
enhance(latest work): exclude featured work
Browse files Browse the repository at this point in the history
  • Loading branch information
mlbrgl committed Mar 6, 2024
1 parent 333ac04 commit 510ce90
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions db/model/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/@ourworldindata/types/src/domainTypes/Author.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface DbRawLatestWork {
id: string
slug: string
title: string
authors: string
Expand All @@ -7,6 +8,7 @@ export interface DbRawLatestWork {
}

export interface DbEnrichedLatestWork {
id: string
slug: string
title: string
authors: string[]
Expand Down
20 changes: 17 additions & 3 deletions site/gdocs/components/ResearchAndWriting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 510ce90

Please sign in to comment.