Skip to content

Commit

Permalink
refactor: resolve internal redirects from db
Browse files Browse the repository at this point in the history
  • Loading branch information
mlbrgl committed Feb 9, 2024
1 parent 329e2f9 commit 8a375ce
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions baker/redirects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as db from "../db/db.js"
import * as wpdb from "../db/wpdb.js"
import { memoize, JsonError, Url } from "@ourworldindata/utils"
import { isCanonicalInternalUrl } from "./formatting.js"
import { resolveExplorerRedirect } from "./replaceExplorerRedirects.js"
Expand Down Expand Up @@ -101,14 +100,12 @@ const stripTrailingSlash = (url: string) => {
}

export const getWordpressRedirectsMap = async () => {
const wordpressRedirectRows = (await wpdb.singleton.query(
`SELECT url, action_data FROM wp_redirection_items WHERE status = 'enabled'`
)) as Array<{ url: string; action_data: string }>
const redirectsFromDb = await getRedirectsFromDb()

return new Map(
wordpressRedirectRows.map((row) => [
stripTrailingSlash(row.url),
stripTrailingSlash(row.action_data),
redirectsFromDb.map((row) => [
stripTrailingSlash(row.source),
stripTrailingSlash(row.target),
])
)
}
Expand Down

0 comments on commit 8a375ce

Please sign in to comment.