Skip to content

Commit 6b39592

Browse files
mgolKrinkle
authored andcommitted
Build: Backport releases.jquery.com prep
This is a backport of commit 2485653 from #70 > 1. Point CDN links directly to https://code.jquery.com. > 2. Add a separate helper for non-SRI CDN links. This is mostly used for CSS > which, in theory, could also have SRI applied but that would require changes to > the SRI plugin so we're leaving CSS without SRI for now. > 3. Add config-sample.json with the new required cdn_origin field. > Defined in infra as of jquery/infrastructure@ffa44e60b4. Differences: * The change to use a `/git` directory for Git files was not included in this backport, as doing so would break the current code.jquery.com site. We can either take the two lines of Nginx config from the new releases-jq site and apply to the old codeorigin-jq in Puppet first, and thus use /git/ on both sites before the transition starts; or we can instead apply the old Nginx config for the top-level files also to releases-jq and perform the adoption of /git/ in the WordPress pages after the transition. Either way could work. For now, in the name of progress, this commit does neither. It backports the known-safe part of the prep commit so that we can deploy and verify the 'cdn_origin' config option, and the other template changes made by this commit.
1 parent 3f2665c commit 6b39592

File tree

7 files changed

+51
-22
lines changed

7 files changed

+51
-22
lines changed

Gruntfile.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,19 @@ grunt.registerTask( "build-index", function() {
304304

305305
var sriHashes = require( "./dist/resources/sri-directives.json" );
306306

307-
function href( file, label ) {
308-
var sri = "sha256-" + sriHashes["@cdn/" + file]["hashes"]["sha256"];
309-
return "<a class='open-sri-modal' href='/" + file + "' data-hash='" + sri + "'>" + label + "</a>";
307+
function cdnSriLink( file, label ) {
308+
var sri = "sha256-" + sriHashes[ `@cdn/${ file }` ].hashes.sha256,
309+
cdnOrigin = grunt.config( "wordpress" ).cdn_origin;
310+
return `<a
311+
class='open-sri-modal'
312+
href='${ cdnOrigin }/${ file }'
313+
data-hash='${ sri }'
314+
>${ label }</a>`;
315+
}
316+
317+
function cdnLink( file, label ) {
318+
var cdnOrigin = grunt.config( "wordpress" ).cdn_origin;
319+
return `<a href='${ cdnOrigin }/${ file }'>${ label }</a>`;
310320
}
311321

312322
Handlebars.registerHelper( "ifeq", function( v1, v2, options ) {
@@ -316,30 +326,48 @@ grunt.registerTask( "build-index", function() {
316326
return options.inverse( this );
317327
} );
318328

319-
Handlebars.registerHelper( "sriLink", function( file, label ) {
320-
return new Handlebars.SafeString( href( file, label ) );
329+
Handlebars.registerHelper( "cdnSriLink", function( file, label ) {
330+
return new Handlebars.SafeString( cdnSriLink( file, label ) );
331+
} );
332+
Handlebars.registerHelper( "cdnLink", function( file, label ) {
333+
return new Handlebars.SafeString( cdnLink( file, label ) );
334+
} );
335+
336+
Handlebars.registerHelper( "concat2",function( p1, p2 ) {
337+
return `${ p1 }${ p2 }`;
338+
} );
339+
Handlebars.registerHelper( "concat3",function( p1, p2, p3 ) {
340+
return `${ p1 }${ p2 }${ p3 }`;
341+
} );
342+
Handlebars.registerHelper( "concat4",function( p1, p2, p3, p4 ) {
343+
return `${ p1 }${ p2 }${ p3 }${ p4 }`;
344+
} );
345+
Handlebars.registerHelper( "concat5",function( p1, p2, p3, p4, p5 ) {
346+
return `${ p1 }${ p2 }${ p3 }${ p4 }${ p5 }`;
321347
} );
322348

323349
Handlebars.registerHelper( "release", function( prefix, release ) {
324-
var html = prefix + " " + release.version + " - " + href( release.filename, "uncompressed" );
350+
var html = prefix + " " + release.version + " - " + cdnSriLink( release.filename, "uncompressed" );
325351
if ( release.minified ) {
326-
html += ", " + href( release.minified, "minified" );
352+
html += ", " + cdnSriLink( release.minified, "minified" );
327353
}
328354
if ( release.packed ) {
329-
html += ", " + href( release.packed, "packed" );
355+
html += ", " + cdnSriLink( release.packed, "packed" );
330356
}
331357
if ( release.slim ) {
332-
html += ", " + href( release.slim, "slim" );
358+
html += ", " + cdnSriLink( release.slim, "slim" );
333359
}
334360
if ( release.slimMinified ) {
335-
html += ", " + href( release.slimMinified, "slim minified" );
361+
html += ", " + cdnSriLink( release.slimMinified, "slim minified" );
336362
}
337363

338364
return new Handlebars.SafeString( html );
339365
} );
340366

341367
Handlebars.registerHelper( "uiTheme", function( release ) {
342-
var url;
368+
var url,
369+
cdnOrigin = grunt.config( "wordpress" ).cdn_origin;
370+
343371
// TODO: link to minified theme if available
344372
if ( release.themes.indexOf( "smoothness" ) !== -1 ) {
345373
url = "smoothness/jquery-ui.css";
@@ -348,7 +376,7 @@ grunt.registerTask( "build-index", function() {
348376
}
349377

350378
return new Handlebars.SafeString(
351-
"<a href='/ui/" + release.version + "/themes/" + url + "'>theme</a>" );
379+
`<a href='${ cdnOrigin }/ui/${ release.version }/themes/${ url }'>theme</a>` );
352380
} );
353381

354382
Handlebars.registerHelper( "include", (function() {

config-sample.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"url": "vagrant.codeorigin.jquery.com",
33
"username": "admin",
44
"password": "secret",
5+
"cdn_origin": "https://code.jquery.com",
56

67
"highwinds": {
78
"api_url": "https://striketracker.highwinds.com",

templates/mobile-release.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<li>
22
jQuery Mobile {{version}} -
3-
<a href="/{{filename}}">uncompressed</a>,
4-
<a href="/{{minified}}">minified</a>,
5-
<a href="/{{minifiedCss}}">theme</a>
3+
{{cdnSriLink filename "uncompressed"}},
4+
{{cdnSriLink minified "minified"}},
5+
{{cdnLink minifiedCss "theme"}}
66
{{#if minifiedStructure}}
7-
(<a href="/{{minifiedStructure}}">structure only</a>)
7+
({{cdnLink minifiedStructure "structure only"}})
88
{{/if}}
99
</li>

templates/pep-release.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<li>
22
PEP {{version}} -
3-
<a href="/{{filename}}">uncompressed</a>,
4-
<a href="/{{minified}}">minified</a>
3+
{{cdnSriLink filename "uncompressed"}},
4+
{{cdnSriLink minified "minified"}}
55
</li>

templates/qunit-release.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<li>
22
QUnit {{version}} -
3-
{{sriLink filename "uncompressed"}},
4-
{{sriLink theme "theme"}}
3+
{{cdnLink filename "uncompressed"}},
4+
{{cdnLink theme "theme"}}
55
</li>

templates/ui-latest.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<li>{{release "jQuery UI" this}}</li>
55
<li>Themes:
66
{{#each themes}}
7-
<a href="/ui/{{../version}}/themes/{{this}}/jquery-ui.css">{{this}}</a>
7+
{{cdnLink (concat5 "ui/" ../version "/themes/" this "/jquery-ui.css") this}}
88
{{/each}}
99
</li>
1010
</ul>

templates/ui.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{{release "jQuery UI" latestStable}}
1111
<h3>Themes</h3>
1212
{{#each latestStable.themes}}
13-
<a href="/ui/{{../latestStable/version}}/themes/{{this}}/jquery-ui.css">{{this}}</a>
13+
{{cdnLink (concat5 "ui/" ../latestStable/version "/themes/" this "/jquery-ui.css") this}}
1414
{{/each}}
1515
{{/if}}
1616
{{#if all.length}}

0 commit comments

Comments
 (0)