@@ -140,12 +140,14 @@ async function transformResponse(response) {
140
140
const injectHostingIntegrations =
141
141
headers . get ( "x-rtd-hosting-integrations" ) || "false" ;
142
142
const forceAddons = headers . get ( "x-rtd-force-addons" ) || "false" ;
143
+ const userJsFile = headers . get ( "x-rtd-user-js-file" ) || "" ;
143
144
const httpStatus = response . status ;
144
145
145
146
// Log some debugging data
146
147
console . log ( `ContentType: ${ contentType } ` ) ;
147
148
console . log ( `X-RTD-Force-Addons: ${ forceAddons } ` ) ;
148
149
console . log ( `X-RTD-Hosting-Integrations: ${ injectHostingIntegrations } ` ) ;
150
+ console . log ( `X-RTD-User-Js-File: ${ userJsFile } ` ) ;
149
151
console . log ( `HTTP status: ${ httpStatus } ` ) ;
150
152
151
153
// Debug mode for some test cases. This is just for triggering an exception
@@ -191,7 +193,7 @@ async function transformResponse(response) {
191
193
// rewriter.on(readthedocsData, new removeElement())
192
194
193
195
rewriter
194
- . on ( "head" , new addPreloads ( ) )
196
+ . on ( "head" , new addPreloads ( userJsFile ) )
195
197
. on (
196
198
"head" ,
197
199
new addMetaTags (
@@ -227,7 +229,7 @@ async function transformResponse(response) {
227
229
//
228
230
if ( forceAddons === "false" && injectHostingIntegrations === "true" ) {
229
231
return new HTMLRewriter ( )
230
- . on ( "head" , new addPreloads ( ) )
232
+ . on ( "head" , new addPreloads ( userJsFile ) )
231
233
. on (
232
234
"head" ,
233
235
new addMetaTags ( projectSlug , versionSlug , resolverFilename , httpStatus ) ,
@@ -267,9 +269,19 @@ class removeElement {
267
269
}
268
270
269
271
class addPreloads {
272
+ constructor ( userJsFile ) {
273
+ this . userJsFile = userJsFile ;
274
+ }
275
+
270
276
element ( element ) {
271
277
console . log ( "addPreloads" ) ;
272
278
element . append ( AddonsConstants . scriptAddons , { html : true } ) ;
279
+
280
+ if ( this . userJsFile ) {
281
+ console . log ( "Adding userJsFile" ) ;
282
+ const userJsFileTag = `<script async type="text/javascript" src="${ this . userJsFile } "></script>` ;
283
+ element . append ( userJsFileTag , { html : true } ) ;
284
+ }
273
285
}
274
286
}
275
287
0 commit comments