Skip to content

Commit

Permalink
馃帀 add hasOutline property to archie Images
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed May 20, 2024
1 parent 020a6ea commit d71f3f2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions db/model/Gdoc/enrichedToRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ export function enrichedBlockToRawBlock(
type: b.type,
value: {
filename: b.filename,
smallFilename: b.smallFilename,
alt: b.alt,
caption: b.caption && spansToHtmlText(b.caption),
size: b.size,
hasOutline: String(b.hasOutline),
},
})
)
Expand Down
13 changes: 13 additions & 0 deletions db/model/Gdoc/rawToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,26 @@ const parseImage = (image: RawBlockImage): EnrichedBlockImage => {
? htmlToSpans(image.value.caption)
: undefined

if (
image.value.hasOutline &&
image.value.hasOutline !== "true" &&
image.value.hasOutline !== "false"
) {
return createError({
message:
"If set, image `hasOutline` property must be true or false",
})
}
const hasOutline = Boolean(image.value.hasOutline === "true")

return {
type: "image",
filename,
smallFilename: image.value.smallFilename,
alt: image.value.alt,
caption,
size,
hasOutline,
originalWidth: undefined,
parseErrors: [],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export type RawBlockImage = {
alt?: string
caption?: string
size?: BlockImageSize
hasOutline?: string
}
}

Expand All @@ -197,6 +198,7 @@ export type EnrichedBlockImage = {
caption?: Span[]
originalWidth?: number
size: BlockImageSize
hasOutline: boolean
} & EnrichedBlockWithParseErrors

export type RawBlockVideo = {
Expand Down
1 change: 1 addition & 0 deletions packages/@ourworldindata/utils/src/Util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ describe(traverseEnrichedBlock, () => {
{
type: "image",
filename: "logo.png",
hasOutline: false,
size: BlockImageSize.Narrow,
parseErrors: [],
},
Expand Down
1 change: 1 addition & 0 deletions site/gdocs/components/ArticleBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export default function ArticleBlock({
filename={block.filename}
smallFilename={block.smallFilename}
alt={block.alt}
hasOutline={block.hasOutline}
containerType={containerType}
/>
{block.caption ? (
Expand Down
9 changes: 8 additions & 1 deletion site/gdocs/components/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ImageMetadata,
getFilenameMIMEType,
} from "@ourworldindata/utils"
import cx from "classnames"
import { LIGHTBOX_IMAGE_CLASS } from "../../Lightbox.js"
import {
IMAGE_HOSTING_R2_BUCKET_SUBFOLDER_PATH,
Expand Down Expand Up @@ -51,17 +52,23 @@ export default function Image(props: {
filename: string
smallFilename?: string
alt?: string
hasOutline?: boolean
className?: string
containerType?: ImageParentContainer
shouldLightbox?: boolean
}) {
const {
filename,
smallFilename,
className = "",
hasOutline,
containerType = "default",
shouldLightbox = true,
} = props

const className = cx(props.className, {
"image--has-outline": hasOutline,
})

const { isPreviewing } = useContext(DocumentContext)
const image = useImage(filename)
const smallImage = useImage(smallFilename)
Expand Down
4 changes: 4 additions & 0 deletions site/gdocs/components/centered-article.scss
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ h3.article-block__heading {
width: 100%;
margin: 32px 0;

& .image--has-outline {
outline: 1px solid #f2f2f2;
}

picture {
// fixes strange extra height that is otherwise added to the element on firefox
display: flex;
Expand Down

0 comments on commit d71f3f2

Please sign in to comment.