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

Adding SRI support to codeorigin.jquery.com #22

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+30 −7
Diff settings

Always

Just for now

Copy path View file
@@ -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" ],

This comment has been minimized.

Copy link
@jmervine

jmervine Feb 1, 2016

Author Contributor

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?

This comment has been minimized.

Copy link
@jdorfman

This comment has been minimized.

Copy link
@scottgonzalez

scottgonzalez Feb 1, 2016

Member

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

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

grunt.registerTask( "build-index", function() {
@@ -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 );
@@ -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" ] );

This comment has been minimized.

Copy link
@jmervine

jmervine Feb 1, 2016

Author Contributor

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" ] );

};
Copy path View file
@@ -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"
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.