From 0ab98dbb04afdaa13bee27bbbefcf42d27a6f169 Mon Sep 17 00:00:00 2001 From: Matthieu Bergel Date: Sun, 18 Feb 2024 09:54:37 +0000 Subject: [PATCH] refactor(redirects): move stripTrailingSlash fn --- baker/redirects.ts | 6 ------ baker/syncRedirectsToGrapher.ts | 8 +++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/baker/redirects.ts b/baker/redirects.ts index 8e4f50e96f6..46872540763 100644 --- a/baker/redirects.ts +++ b/baker/redirects.ts @@ -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() diff --git a/baker/syncRedirectsToGrapher.ts b/baker/syncRedirectsToGrapher.ts index 458551f2b26..d92452bd720 100644 --- a/baker/syncRedirectsToGrapher.ts +++ b/baker/syncRedirectsToGrapher.ts @@ -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 @@ -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 => { const allWordpressRedirectsRaw = await wpdb.FOR_SYNC_ONLY_getRedirects()