Skip to content

Commit

Permalink
🐝 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Dec 11, 2023
1 parent 0c7f254 commit 82fde64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
19 changes: 1 addition & 18 deletions db/migrateWpPostsToArchieMl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
OwidGdocType,
RelatedChart,
EnrichedBlockAllCharts,
OwidEnrichedGdocBlock,
} from "@ourworldindata/utils"
import * as Post from "./model/Post.js"
import fs from "fs"
Expand All @@ -17,6 +16,7 @@ import {
withoutEmptyOrWhitespaceOnlyTextBlocks,
convertAllWpComponentsToArchieMLBlocks,
adjustHeadingLevels,
findMinimumHeadingLevel,
} from "./model/Gdoc/htmlToEnriched.js"
import { getRelatedCharts, isPostCitable } from "./wpdb.js"
import { parsePostAuthors } from "./model/Post.js"
Expand Down Expand Up @@ -288,21 +288,4 @@ const migrate = async (): Promise<void> => {
}
}

function findMinimumHeadingLevel(blocks: OwidEnrichedGdocBlock[]): number {
let minBlockLevel = 6
for (const block of blocks) {
if (block.type === "heading") {
minBlockLevel = Math.min(block.level, minBlockLevel)
} else if ("children" in block) {
minBlockLevel = Math.min(
findMinimumHeadingLevel(
block.children as OwidEnrichedGdocBlock[]
),
minBlockLevel
)
}
}
return minBlockLevel
}

migrate()
19 changes: 19 additions & 0 deletions db/model/Gdoc/htmlToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,25 @@ export function convertAllWpComponentsToArchieMLBlocks(
})
}

export function findMinimumHeadingLevel(
blocks: OwidEnrichedGdocBlock[]
): number {
let minBlockLevel = 6
for (const block of blocks) {
if (block.type === "heading") {
minBlockLevel = Math.min(block.level, minBlockLevel)
} else if ("children" in block) {
minBlockLevel = Math.min(
findMinimumHeadingLevel(
block.children as OwidEnrichedGdocBlock[]
),
minBlockLevel
)
}
}
return minBlockLevel
}

export function adjustHeadingLevels(
blocks: OwidEnrichedGdocBlock[],
minHeadingLevel: number,
Expand Down

0 comments on commit 82fde64

Please sign in to comment.