Skip to content

Commit

Permalink
Refactor to reuse the position of the hash in the file name
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgroves committed Aug 30, 2019
1 parent 1b82b75 commit 7b65a1a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down

0 comments on commit 7b65a1a

Please sign in to comment.