Skip to content

Commit

Permalink
Fix global asset not found for preview
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshino committed Nov 9, 2024
1 parent e8fe275 commit e420c76
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib/services/assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ export const getAssetByPath = (savedPath, { entry, collection } = {}) => {
return undefined;
}

let { internalPath } =
// eslint-disable-next-line prefer-const
let { internalPath, collectionName } =
get(allAssetFolders).findLast((folder) =>
publicPath.match(`^${folder.publicPath.replace(/{{.+?}}/g, '.+?')}\\b`),
) ?? {};
Expand All @@ -353,6 +354,16 @@ export const getAssetByPath = (savedPath, { entry, collection } = {}) => {
return undefined;
}

// Find a global/uncategorized asset
if (!collectionName) {
const fullPath = savedPath.replace(new RegExp(`^${escapeRegExp(publicPath)}`), internalPath);
const globalAsset = get(allAssets).find((asset) => asset.path === fullPath);

if (globalAsset) {
return globalAsset;
}
}

if (entry && !collection) {
[collection] = getCollectionsByEntry(entry);
}
Expand Down

0 comments on commit e420c76

Please sign in to comment.