Skip to content

Commit

Permalink
🎉 add Max as default author
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Nov 6, 2023
1 parent 6d2226f commit 1d43c30
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions db/migrateWpPostsToArchieMl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
OwidGdocType,
RelatedChart,
EnrichedBlockAllCharts,
FullPost,

Check warning on line 11 in db/migrateWpPostsToArchieMl.ts

View workflow job for this annotation

GitHub Actions / eslint

'FullPost' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 11 in db/migrateWpPostsToArchieMl.ts

View workflow job for this annotation

GitHub Actions / eslint

'FullPost' is defined but never used. Allowed unused vars must match /^_/u
} from "@ourworldindata/utils"
import * as Post from "./model/Post.js"
import fs from "fs"
Expand All @@ -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
Expand Down Expand Up @@ -92,18 +93,30 @@ const migrate = async (): Promise<void> => {
"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
Expand Down

0 comments on commit 1d43c30

Please sign in to comment.