Skip to content

Commit

Permalink
✨ make lightning prop declaration more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Oct 13, 2023
1 parent ecb6c3c commit c1af746
Showing 1 changed file with 64 additions and 23 deletions.
87 changes: 64 additions & 23 deletions adminSiteClient/gdocsDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,70 @@ export const checkIsLightningUpdate = (
nextGdoc: OwidGdocInterface,
hasChanges: boolean
) => {
const lightningArticleProps: Array<keyof OwidGdocInterface> = [
"updatedAt",
"linkedDocuments",
"imageMetadata",
"linkedCharts",
"errors",
"revisionId",
]
// lightning props are props that do not require a full rebake of the site if changed, because
// their impact is limited to just this article. They are marked as "true" in these two config maps.
// The props that *do* require a full rebake if changed are marked "false".
const lightningPropConfigMap: Record<
Exclude<keyof OwidGdocInterface, "content">,
boolean
> = {
breadcrumbs: true,
errors: true,
imageMetadata: true,
linkedCharts: true,
linkedDocuments: true,
relatedCharts: true,
revisionId: true,
updatedAt: true,
createdAt: false,
id: false, // weird case - can't be updated
publicationContext: false, // requires an update of the blog roll
published: false, // requires an update of the blog roll
publishedAt: false, // could require an update of the blog roll
slug: false, // requires updating any articles that link to it
tags: false, // requires updating related articles on grapher pages
}

const lightningContentProps: Array<keyof OwidGdocContent> = [
"body",
"subtitle",
"toc",
"supertitle",
"refs",
"summary",
"cover-image",
"cover-color",
]
const lightningPropContentConfigMap: Record<
keyof OwidGdocContent,
boolean
> = {
"cover-color": true,
"cover-image": true,
"hide-citation": true,
body: true,
dateline: true,
details: true,
refs: true,
subtitle: true,
summary: true,
"sticky-nav": true,
supertitle: true,
toc: true,
"atom-excerpt": false, // requires updating the atom feed / blog roll
"atom-title": false, // requires updating the atom feed / blog roll
"featured-image": false, // requires updating references to this article
authors: false, // requires updating references to this article
excerpt: false, // requires updating references to this article
faqs: false, // requires updating datapages
parsedFaqs: false, // requires updating datapages
title: false, // requires updating references to this article
type: false, // could require updating other content if switching type to fragment
}

const getLightningPropKeys = (configMap: Record<string, boolean>) =>
Object.entries(configMap)
.filter(([_, isLightningProp]) => isLightningProp)
.map(([key]) => key)

const lightningPropKeys = getLightningPropKeys(lightningPropConfigMap)
const lightningPropContentKeys = getLightningPropKeys(
lightningPropContentConfigMap
)

const lightningProps = [
...lightningArticleProps,
...lightningContentProps.map((prop) => `content.${prop}`),
const keysToOmit = [
...lightningPropKeys,
...lightningPropContentKeys.map((key) => `content.${key}`),
]

// When this function is called from server-side code and a Gdoc object
Expand All @@ -59,11 +100,11 @@ export const checkIsLightningUpdate = (
// issue with Dates and date strings.
const prevOmitted = omit(
{ ...prevGdoc, tags: nextGdoc.tags?.map((tag) => JSON.stringify(tag)) },
lightningProps
keysToOmit
)
const nextOmitted = omit(
{ ...nextGdoc, tags: prevGdoc.tags?.map((tag) => JSON.stringify(tag)) },
lightningProps
keysToOmit
)

return (
Expand Down

0 comments on commit c1af746

Please sign in to comment.