Skip to content

Commit

Permalink
Attempted fix for image links (#391)
Browse files Browse the repository at this point in the history
* Use path.join in transformSrc

* Replace improper use of path.join with simpler fix

* Handle dir="" case

* Tweak the bug fix
  • Loading branch information
3b1b committed Jan 24, 2024
1 parent 273e2d3 commit 9d28176
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions util/transformSrc.js
Original file line number Diff line number Diff line change
@@ -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")) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 9d28176

Please sign in to comment.