Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cache busting for meta tags #165

Merged
merged 1 commit into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ Remote URLs for CSS, JavaScript, and images are ignored by cacheBust. This assum

### Change Log

**v0.6.1**
* Support cache busting for meta tags

**v0.6.0**
* Support cache busting for video tag
* Fix CSS processing for media queries with comments
Expand Down
10 changes: 10 additions & 0 deletions config/metas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
options: {
baseDir: 'tmp/metas'
},
files: [{
expand: true,
cwd: 'tmp/metas/',
src: ['*.html']
}]
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-cache-bust",
"description": "Bust static assets from the cache using content hashing",
"version": "0.6.0",
"version": "0.6.1",
"author": "Ben Holland <[email protected]>",
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions tasks/lib/defaultFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module.exports = {
'link[rel="stylesheet"]': function() {
return this.attribs['href'];
},
'meta[property]': function() {
return this.attribs.content;
},
'img': [
function() {
return this.attribs.src;
Expand Down
4 changes: 4 additions & 0 deletions tasks/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ module.exports = {
filePath = element.attribs.href;
}

if (element.attribs.content) {
filePath = element.attribs.content;
}

return filePath ? this.checkIfValidFile(url.parse(filePath), cdnPath) : false;
},

Expand Down
Binary file added tests/metas/assets/image1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/metas/assets/image1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/metas/assets/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/metas/metas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<meta property="og:image" content="assets/image1.jpg">
<meta property="og:image" content="assets/image1.png">
<meta property="og:image" content="assets/image1.gif">
19 changes: 19 additions & 0 deletions tests/metas/metas_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

var grunt = require('grunt');

module.exports = {

metas: function(test) {
test.expect(3);

var markup = grunt.file.read('tmp/metas/metas.html');

test.ok(markup.match(/image1\.[a-z0-9]{16}\.jpg/), 'testing meta .jpg');
test.ok(markup.match(/image1\.[a-z0-9]{16}\.png/), 'testing meta .png');
test.ok(markup.match(/image1\.[a-z0-9]{16}\.gif/), 'testing meta .gif');

test.done();
}

};