From 3c97a509c693aee282e9bec6a8e2b0be706a9f83 Mon Sep 17 00:00:00 2001 From: Ferenc Szalai Date: Sun, 29 Mar 2020 17:15:51 +0200 Subject: [PATCH 1/2] Returning empty string from either assertPath or publicUrl allows to skip that asset to download --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 1454699..3bce971 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,11 @@ module.exports.transform = async ({ data, debug, log, options }) => { ? options.publicUrl(null, entry, assetPath) : options.publicUrl; - result.set(regExp, { assetPath, publicUrl }); + + if (assetPath && publicUrl) { + debug("Found asset %s, %s", assetPath, publicUrl); + result.set(regExp, { assetPath, publicUrl }); + } return result; }, new Map()); @@ -62,8 +66,10 @@ module.exports.transform = async ({ data, debug, log, options }) => { ? options.publicUrl(entry, value, assetPath) : options.publicUrl; - filesToDownload[value.url] = path.join(process.cwd(), assetPath); - replacedFields[fieldName] = publicUrl; + if (assetPath && publicUrl) { + filesToDownload[value.url] = path.join(process.cwd(), assetPath); + replacedFields[fieldName] = publicUrl; + } } else if (typeof entry[fieldName] === "string") { assets.forEach(({ assetPath, publicUrl }, expression) => { let isMatch = false; From 788f7006cb719228230f855e7034a2a1cbc85385 Mon Sep 17 00:00:00 2001 From: Ferenc Szalai Date: Sun, 29 Mar 2020 17:20:26 +0200 Subject: [PATCH 2/2] add documentation of assetPath and publicUrl new behaviour --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 933d2be..10d07bb 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ If `assetPath` is a function, it will be invoked for each asset detected with tw - `entry` (Object): The entry in which the asset was detected - `asset` (Object): The normalized asset object -Its return value will be used as the path for the asset. +Its return value will be used as the path for the asset. If its return empty string then the asset is skipped from donwload. ### `publicUrl` @@ -55,7 +55,7 @@ If `publicUrl` is a function, it will be invoked for each asset detected with tw - `asset` (Object): The normalized asset object - `assetPath` (String): The local path where the asset has been saved -Its return value will replace the original URL of the asset in any objects. +Its return value will replace the original URL of the asset in any objects. If its return empty string then the asset is skipped from donwload. ### 👀 Example configuration