From 7b65a1a20ed029769238675c59765976771b2328 Mon Sep 17 00:00:00 2001 From: Daniel Groves Date: Fri, 30 Aug 2019 10:28:48 +0100 Subject: [PATCH] Refactor to reuse the position of the hash in the file name --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7095df2..9229b86 100644 --- a/index.js +++ b/index.js @@ -92,14 +92,15 @@ const staticify = (root, options) => { const fileName = path.basename(p); const fileNameParts = fileName.split('.'); - const fileNameHash = fileNameParts[fileNameParts.length - 2]; + const fileNameHashPosition = fileNameParts.length - 2; + const fileNameHash = fileNameParts[fileNameHashPosition]; const re = new RegExp(`^[0-9a-f]{${HASH_LEN}}$`, 'i'); const reResult = re.exec(fileNameHash); if (fileNameParts.length >= 3 && fileNameHash.length === HASH_LEN && (reResult && reResult[0] === fileNameHash) ) { - const stripped = fileNameParts.slice(0, fileNameParts.length - 2); + const stripped = fileNameParts.slice(0, fileNameHashPosition); stripped.push(fileNameParts[fileNameParts.length - 1]);