Skip to content

Commit 97ff3c2

Browse files
committed
Strip media_folder prefix when resolving assets
Fix #651
1 parent e29f72b commit 97ff3c2

2 files changed

Lines changed: 194 additions & 1 deletion

File tree

src/lib/services/assets/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@ export const getAssetByRelativePathAndCollection = ({ path, entry, collection, f
148148
}
149149

150150
const { entryFolder } = entryFilePath.match(/(?<entryFolder>.+?)(?:\/[^/]+)?$/)?.groups ?? {};
151-
const resolvedPath = resolvePath(createPath([entryFolder, mediaFolder, path]));
151+
152+
// Strip the `media_folder` prefix from the stored path before joining with `mediaFolder`, to
153+
// avoid duplication when the stored value already includes the media folder (e.g.
154+
// `images/photo.jpg`).
155+
const localPath =
156+
mediaFolder && path.startsWith(`${mediaFolder}/`) ? path.slice(mediaFolder.length + 1) : path;
157+
158+
const resolvedPath = resolvePath(createPath([entryFolder, mediaFolder, localPath]));
152159

153160
return get(allAssets).find((asset) => asset.path === resolvedPath);
154161
};

src/lib/services/assets/index.test.js

Lines changed: 186 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)