-
Notifications
You must be signed in to change notification settings - Fork 596
Adding SRI support to codeorigin.jquery.com #22
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,26 @@ var _ = require( "underscore" ), | |
http = require( "http" ); | ||
|
||
grunt.loadNpmTasks( "grunt-jquery-content" ); | ||
grunt.loadNpmTasks( "grunt-sri" ); | ||
|
||
grunt.initConfig({ | ||
wordpress: (function() { | ||
var config = require( "./config" ); | ||
config.dir = "dist/wordpress"; | ||
return config; | ||
})() | ||
})(), | ||
sri: { | ||
generate: { | ||
src: [ | ||
"cdn/**/*.js", | ||
"cdn/**/*.css" | ||
], | ||
options: { | ||
algorithms: ["sha256"], | ||
dest: "./sri-directives.json" | ||
} | ||
} | ||
} | ||
}); | ||
|
||
grunt.registerTask( "build-index", function() { | ||
|
@@ -265,15 +278,25 @@ grunt.registerTask( "build-index", function() { | |
}; | ||
} | ||
|
||
var sriHashes = require("./sri-directives.json"); | ||
Handlebars.registerHelper( "release", function( prefix, release ) { | ||
var html = prefix + " " + release.version + " - " + | ||
"<a href='/" + release.filename + "'>uncompressed</a>"; | ||
var sri = function(filename) { | ||
var hashes = sriHashes["@cdn/" + filename]["hashes"]; | ||
return "sha256-" + hashes["sha256"]; | ||
}; | ||
|
||
var href = function(key, label) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say this should move out too, and the value from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upon moving this out, I decided that a seperate |
||
label = (label === undefined ? key : label); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this line would go away if the above is implemented ( |
||
return "<a class='open-sri-modal' href='/" + release[key] + "' data-hash='" + sri(release[key]) + "'>" + label + "</a>"; | ||
}; | ||
|
||
var html = prefix + " " + release.version + " - " + href("filename", "uncompressed"); | ||
|
||
if ( release.minified ) { | ||
html += ", <a href='/" + release.minified + "'>minified</a>"; | ||
html += ", " + href("minified"); | ||
} | ||
if ( release.packed ) { | ||
html += ", <a href='/" + release.packed + "'>packed</a>"; | ||
html += ", " + href("packed"); | ||
} | ||
|
||
return new Handlebars.SafeString( html ); | ||
|
@@ -360,7 +383,7 @@ grunt.registerTask( "reload-listings", function() { | |
}); | ||
}); | ||
|
||
grunt.registerTask( "build", [ "build-index" ] ); | ||
grunt.registerTask( "build", [ "sri:generate", "build-index" ] ); | ||
grunt.registerTask( "deploy", [ "wordpress-deploy", "reload-listings" ] ); | ||
|
||
}; |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be defined outside of the helper so that it's only ever defined once.