Skip to content

Commit

Permalink
refactor(redirects): move stripTrailingSlash fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mlbrgl committed Feb 19, 2024
1 parent 88681d0 commit 0ab98db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 0 additions & 6 deletions baker/redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ export const getGrapherRedirectsMap = async (
)
}

export const stripTrailingSlash = (url: string) => {
if (url === "/") return url

return url.replace(/\/$/, "") // remove trailing slash: /abc/ -> /abc
}

export const getWordpressRedirectsMap = async () => {
const redirectsFromDb = await getRedirectsFromDb()

Expand Down
8 changes: 7 additions & 1 deletion baker/syncRedirectsToGrapher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as db from "../db/db"
import * as wpdb from "../db/wpdb"
import { getRedirectsFromDb } from "../db/model/Redirect.js"
import { stripTrailingSlash, resolveRedirectFromMap } from "./redirects.js"
import { resolveRedirectFromMap } from "./redirects.js"
import { Redirect, Url } from "@ourworldindata/utils"

// A close cousing of the getWordpressRedirectsMap() function from
Expand All @@ -12,6 +12,12 @@ const getWordpressRedirectsMapFromRedirects = (
return new Map(redirects.map((r) => [r.source, r.target]))
}

const stripTrailingSlash = (url: string) => {
if (url === "/") return url

return url.replace(/\/$/, "") // remove trailing slash: /abc/ -> /abc
}

export const syncRedirectsToGrapher = async (): Promise<void> => {
const allWordpressRedirectsRaw = await wpdb.FOR_SYNC_ONLY_getRedirects()

Expand Down

0 comments on commit 0ab98db

Please sign in to comment.