diff --git a/db/migrateWpPostsToArchieMl.ts b/db/migrateWpPostsToArchieMl.ts index 74a380d1706..da4ca579904 100644 --- a/db/migrateWpPostsToArchieMl.ts +++ b/db/migrateWpPostsToArchieMl.ts @@ -8,6 +8,7 @@ import { OwidGdocType, RelatedChart, EnrichedBlockAllCharts, + FullPost, } from "@ourworldindata/utils" import * as Post from "./model/Post.js" import fs from "fs" @@ -17,7 +18,7 @@ import { convertAllWpComponentsToArchieMLBlocks, adjustHeadingLevels, } from "./model/Gdoc/htmlToEnriched.js" -import { getRelatedCharts } from "./wpdb.js" +import { getRelatedCharts, isPostCitable } from "./wpdb.js" import { parsePostAuthors } from "./model/Post.js" // slugs from all the linear entries we want to migrate from @edomt @@ -92,18 +93,30 @@ const migrate = async (): Promise => { "created_at_in_wordpress", "updated_at", "featured_image" - ).from(db.knexTable(Post.postsTable)) // .where("id", "=", "58149")) + ).from(db.knexTable(Post.postsTable).where("id", "=", "23144")) for (const post of posts) { try { const isEntry = entries.has(post.slug) - console.log("isEntry", isEntry) const text = post.content let relatedCharts: RelatedChart[] = [] if (isEntry) { relatedCharts = await getRelatedCharts(post.id) } + const shouldIncludeMaxAsAuthor = await isPostCitable( + // Only needs post.slug + post as any + ) + if ( + shouldIncludeMaxAsAuthor && + !post.authors.includes("Max Roser") + ) { + const authorsJson = JSON.parse(post.authors) + authorsJson.push({ author: "Max Roser", order: Infinity }) + post.authors = JSON.stringify(authorsJson) + } + // We don't get the first and last nodes if they are comments. // This can cause issues with the wp:components so here we wrap // everything in a div