cache-bust-filename
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "cache-bust-filename", | ||
"description": "Cache bust by adding an md5 to file names.", | ||
"description": "Cache bust urls by including a hash in filenames.", | ||
"homepage": "https://github.com/kayomarz/cache-bust-filename#readme", | ||
@@ -13,3 +13,5 @@ "repository": { | ||
"CSS", | ||
"HTML" | ||
"HTML", | ||
"eleventy", | ||
"11ty" | ||
], | ||
@@ -24,3 +26,3 @@ "author": { | ||
"main": "index.js", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"scripts": { | ||
@@ -27,0 +29,0 @@ "test": "jest", |
# Cache busting | ||
Cache busting urls by updating file names. | ||
Cache bust urls by including a hash in filenames. | ||
@@ -80,4 +80,8 @@ **Note**: Currently, this library cache busts a single css `<link>` | ||
## Version 0.1.2 | ||
+ Handle condition when no links are found. | ||
## Version 0.1.0 | ||
+ Cache busts a single css `<link>` found in an HTML file. |
@@ -47,4 +47,2 @@ const {readFileSync, renameSync} = require("fs"); | ||
} | ||
const newFile = join(dir_out, newUrl); | ||
renameSync(linkFile, newFile); | ||
@@ -58,13 +56,17 @@ const replacer = getReplacer(ext, linkUrl, newUrl); | ||
const found = replace.sync(opts); | ||
printSummary(dir_out, linkUrl, found); | ||
const edited = found.filter(f => f.hasChanged === true); | ||
printSummary(dir_out, linkUrl, found, edited); | ||
if (edited.length > 0) | ||
{ | ||
const newFile = join(dir_out, newUrl); | ||
renameSync(linkFile, newFile); | ||
} | ||
} | ||
function printSummary(dir_out, linkUrl, found) { | ||
const changed = found.filter(f => f.hasChanged === true); | ||
const ok = (found.length > 0) && (found.length === changed.length); | ||
if (!ok) { | ||
err(`found:${found.length}, changed:${changed.length}.`); | ||
} | ||
function printSummary(dir_out, linkUrl, found, edited) { | ||
const ok = (found.length > 0) && (found.length === edited.length); | ||
log(`found:${found.length} files, edited:${edited.length}.`); | ||
function strFiles() { | ||
const shortPaths = changed.map(i => relative(dir_out, i.file)); | ||
const shortPaths = edited.map(i => relative(dir_out, i.file)); | ||
return shortPaths.join(", "); | ||
@@ -71,0 +73,0 @@ } |
9284
9
207
87
4