diff --git a/util/transformSrc.js b/util/transformSrc.js index 9162ebd2..a7cd24a7 100644 --- a/util/transformSrc.js +++ b/util/transformSrc.js @@ -1,5 +1,10 @@ import { bucket } from "../data/site.yaml"; +function ensureLeadingSlash(str) { + if (str && !str.startsWith("/")) return "/" + str; + return str; +} + // change provided srcs (png & mp4) to external bucket location for production. export const transformSrc = (src, dir = "") => { if (src.endsWith(".mp4")) { @@ -10,10 +15,10 @@ export const transformSrc = (src, dir = "") => { return src; } else if ( process.env.NODE_ENV === "production" && - process.env.NEXT_PUBLIC_NETLIFY_CONTEXT === "production" && // Not a deploy preview + // process.env.NEXT_PUBLIC_NETLIFY_CONTEXT === "production" && // Not a deploy preview !src.endsWith("svg") ) { - return bucket + dir + src; + return bucket + ensureLeadingSlash(dir + src); } else { return dir + src; }