Skip to content

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

Closed
wants to merge 4 commits into from
Closed
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
36 changes: 29 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering creating a constant of this to support quickly changing this to 512 in the future, something like:

const SRI_ENCODING = "sha256"; // near the top

// ... code
                algorithms: [ SRI_ENCODING ],

Thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanKingston your thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not necessary. Also, we can't use const yet.

dest: "dist/resources/sri-directives.json"
}
}
}
});

grunt.registerTask( "build-index", function() {
Expand Down Expand Up @@ -265,15 +278,19 @@ grunt.registerTask( "build-index", function() {
};
}

Handlebars.registerHelper( "release", function( prefix, release ) {
var html = prefix + " " + release.version + " - " +
"<a href='/" + release.filename + "'>uncompressed</a>";
var sriHashes = require( "./dist/resources/sri-directives.json" );
function href( file, label ) {
var sri = "sha256-" + sriHashes[ "@cdn/" + file ][ "hashes" ][ "sha256" ];
return "<a class='open-sri-modal' href='/" + file + "' data-hash='" + sri + "'>" + label + "</a>";
}

Handlebars.registerHelper( "release", function( prefix, release ) {
var html = prefix + " " + release.version + " - " + href( release.filename, "uncompressed" );
if ( release.minified ) {
html += ", <a href='/" + release.minified + "'>minified</a>";
html += ", " + href( release.minified, "minified" );
}
if ( release.packed ) {
html += ", <a href='/" + release.packed + "'>packed</a>";
html += ", " + href( release.packed, "packed" );
}

return new Handlebars.SafeString( html );
Expand Down Expand Up @@ -360,7 +377,12 @@ grunt.registerTask( "reload-listings", function() {
});
});

grunt.registerTask( "build", [ "build-index" ] );
grunt.registerTask( "ensure-dist-resources", function() {
grunt.file.mkdir( "dist/resources" );
});

grunt.registerTask( "sri-generate", [ "ensure-dist-resources", "sri:generate" ] );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I registered this as such because sri:generate will fail without this step.

grunt.registerTask( "build", [ "sri-generate", "build-index" ] );
grunt.registerTask( "deploy", [ "wordpress-deploy", "reload-listings" ] );

};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"grunt": "0.4.5",
"grunt-jquery-content": "3.0.0",
"grunt-sri": "0.0.5",
"semver": "2.0.11",
"underscore": "1.5.1",
"handlebars": "1.0.12"
Expand Down