diff --git a/baker/postUpdatedHook.ts b/baker/postUpdatedHook.ts index 9d926cbe5cb..7808961c062 100644 --- a/baker/postUpdatedHook.ts +++ b/baker/postUpdatedHook.ts @@ -4,7 +4,7 @@ import parseArgs from "minimist" import { BAKE_ON_CHANGE } from "../settings/serverSettings.js" import { DeployQueueServer } from "./DeployQueueServer.js" import { exit } from "../db/cleanup.js" -import { PostRow } from "@ourworldindata/utils" +import { PostRow, extractFormattingOptions } from "@ourworldindata/utils" import * as wpdb from "../db/wpdb.js" import * as db from "../db/db.js" import { @@ -94,6 +94,9 @@ const syncPostToGrapher = async ( const existsInGrapher = !!matchingRows.length const wpPost = rows[0] + + const formattingOptions = extractFormattingOptions(wpPost.post_content) + const postRow = wpPost ? ({ id: wpPost.ID, @@ -117,6 +120,7 @@ const syncPostToGrapher = async ( wpPost.created_at === zeroDateString ? "1970-01-01 00:00:00" : wpPost.created_at, + formattingOptions: formattingOptions, } as PostRow) : undefined @@ -130,13 +134,19 @@ const syncPostToGrapher = async ( ) postRow.content = contentWithBlocksInlined + const rowForDb = { + ...postRow, + // TODO: it's not nice that we have to stringify this here + formattingOptions: JSON.stringify(postRow.formattingOptions), + } + if (!existsInGrapher) - await transaction.table(postsTable).insert(postRow) + await transaction.table(postsTable).insert(rowForDb) else if (existsInGrapher) await transaction .table(postsTable) - .where("id", "=", postRow.id) - .update(postRow) + .where("id", "=", rowForDb.id) + .update(rowForDb) } }) diff --git a/db/syncPostsToGrapher.ts b/db/syncPostsToGrapher.ts index 2a7d8285747..bfaa700dc91 100644 --- a/db/syncPostsToGrapher.ts +++ b/db/syncPostsToGrapher.ts @@ -293,6 +293,7 @@ const syncPostsToGrapher = async (): Promise => { type: post.post_type, status: post.post_status, content: dereferenceReusableBlocksFn(content), + featured_image: post.featured_image || "", published_at: post.post_date_gmt === zeroDateString ? null @@ -305,12 +306,11 @@ const syncPostsToGrapher = async (): Promise => { excerpt: post.post_excerpt, created_at_in_wordpress: post.created_at === zeroDateString ? null : post.created_at, - featured_image: post.featured_image || "", formattingOptions: formattingOptions, } }) as PostRow[] const postLinks = await PostLink.find() - const postLinksById = groupBy(postLinks, (link) => link.sourceId) + const postLinksById = groupBy(postLinks, (link: PostLink) => link.sourceId) const linksToAdd: PostLink[] = [] const linksToDelete: PostLink[] = []