From 62d00a4e754072d01a1c375130a1fdefc3c7a068 Mon Sep 17 00:00:00 2001 From: gmierz Date: Wed, 18 May 2022 22:52:28 -0400 Subject: [PATCH] Add option to store url as hash. --- lib/support/pathToFolder.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/support/pathToFolder.js b/lib/support/pathToFolder.js index b71b17c0d5..274471b696 100644 --- a/lib/support/pathToFolder.js +++ b/lib/support/pathToFolder.js @@ -42,9 +42,11 @@ module.exports = function (url, options) { } // This is used from sitespeed.io to match URLs on Graphite - if (!options.storeURLsAsFlatPageOnDisk) { - pathSegments.push(...urlSegments); - } else { + if (options.storeURLsAsHash) { + const md5 = crypto.createHash('md5') + const hash = md5.update(url).digest('hex').substring(0, 8); + pathSegments.push(hash); + } else if (options.storeURLsAsFlatPageOnDisk) { const folder = toSafeKey(urlSegments.join('_').concat('_')); if (folder.length > 255) { log.info( @@ -54,6 +56,8 @@ module.exports = function (url, options) { } else { pathSegments.push(folder); } + } else { + pathSegments.push(...urlSegments); } }