-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Financial-Times/hashed-asset-helper
hack together a hashed asset helper
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
module.exports = function(options) { | ||
var assetHash; | ||
var file = options.fn(this); | ||
try { | ||
assetHash = require(options.data.root.__rootDirectory + '/public/' + file + '-asset-hash.json')[file]; | ||
} catch(err) { | ||
if (process.env.NODE_ENV === 'production') { | ||
throw new Error("./public/" + file + "-asset-hash.json not found, required for proper working of the application in production"); | ||
} else { | ||
console.warn("./public/" + file + "-asset-hash.json not found. Falling back to un-fingerprinted files."); | ||
} | ||
} | ||
if (assetHash) { | ||
file = assetHash; | ||
} | ||
return '/' + options.data.root.__name+'/' + file; | ||
}; |