Skip to content

Commit

Permalink
Add optional url to person block
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyi committed Dec 17, 2024
1 parent 119e14e commit 587f6d9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
12 changes: 11 additions & 1 deletion db/model/Gdoc/GdocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ export class GdocBase implements OwidGdocBaseInterface {
block: OwidEnrichedGdocBlock
): DbInsertPostGdocLink[] | void {
const links: DbInsertPostGdocLink[] = match(block)
.with({ type: "person" }, (block) => {
if (!block.url) return []
return [
createLinkFromUrl({
url: block.url,
source: this,
componentType: block.type,
text: block.name,
}),
]
})
.with({ type: "prominent-link" }, (block) => [
createLinkFromUrl({
url: block.url,
Expand Down Expand Up @@ -559,7 +570,6 @@ export class GdocBase implements OwidGdocBaseInterface {
"numbered-list",
"people",
"people-rows",
"person",
"pull-quote",
"sdg-grid",
"sdg-toc",
Expand Down
1 change: 1 addition & 0 deletions db/model/Gdoc/rawToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ const parsePerson = (raw: RawBlockPerson): EnrichedBlockPerson => {
image: raw.value.image,
name: raw.value.name,
title: raw.value.title,
url: extractUrl(raw.value.url),
text: raw.value.text.map(parseText),
socials: raw.value.socials?.map(parseSocialLink),
parseErrors: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export type RawBlockPerson = {
image?: string
name: string
title?: string
url?: string
text: RawBlockText[]
socials?: RawSocialLink[]
}
Expand All @@ -305,6 +306,7 @@ export type EnrichedBlockPerson = {
image?: string
name: string
title?: string
url?: string
text: EnrichedBlockText[]
socials?: EnrichedSocialLink[]
} & EnrichedBlockWithParseErrors
Expand Down
4 changes: 4 additions & 0 deletions site/gdocs/components/Person.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
flex-direction: column;
gap: 2px;
margin-bottom: 8px;

a {
color: inherit;
}
}

.person-heading {
Expand Down
21 changes: 17 additions & 4 deletions site/gdocs/components/Person.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import * as React from "react"
import { useMediaQuery } from "usehooks-ts"

import { EnrichedBlockPerson } from "@ourworldindata/types"
import { getCanonicalUrl } from "@ourworldindata/components"
import { EnrichedBlockPerson, OwidGdocType } from "@ourworldindata/types"
import { SMALL_BREAKPOINT_MEDIA_QUERY } from "../../SiteConstants.js"
import { useLinkedDocument } from "../utils.js"
import { ArticleBlocks } from "./ArticleBlocks.js"
import Image from "./Image.js"
import { useMediaQuery } from "usehooks-ts"
import { SMALL_BREAKPOINT_MEDIA_QUERY } from "../../SiteConstants.js"
import { Socials } from "./Socials.js"

export default function Person({ person }: { person: EnrichedBlockPerson }) {
const { linkedDocument } = useLinkedDocument(person.url ?? "")
const isSmallScreen = useMediaQuery(SMALL_BREAKPOINT_MEDIA_QUERY)

const slug = linkedDocument?.slug
const url = slug
? getCanonicalUrl("", {
slug,
content: { type: OwidGdocType.Author },
})
: undefined

const heading = <h3 className="person-heading h2-bold">{person.name}</h3>

const header = (
<div className="person-header">
<h3 className="person-heading h2-bold">{person.name}</h3>
{url ? <a href={url}>{heading}</a> : heading}
{person.title && (
<span className="person-title">{person.title}</span>
)}
Expand Down

0 comments on commit 587f6d9

Please sign in to comment.