Skip to content

Commit 8aceef1

Browse files
victorquinnknownasilya
authored andcommitted
Fix bug where docpress would not load external scripts (#172)
* Fix bug where docpress would not load external scripts * Remove new
1 parent dd0e548 commit 8aceef1

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const ware = require('ware')
44
const fs = require('fs')
55
const pug = require('pug')
66
const join = require('path').join
7+
const url = require('url')
78
const assign = Object.assign
89

910
const hash = require('./lib/hash')
@@ -125,10 +126,18 @@ function addJs (files, ms, done) {
125126

126127
if (Array.isArray(scripts)) {
127128
let userScripts = scripts.map((location) => {
128-
let file = files[location]
129-
if (!file.contents) return
130-
let fileHash = hash(file.contents)
131-
return `${location}?t=${fileHash}`
129+
// Need to check if local or external
130+
let fileUrl = url.parse(location, false, true)
131+
if (fileUrl.host === null) {
132+
// Local url
133+
let file = files[location]
134+
if (!file.contents) return
135+
let fileHash = hash(file.contents)
136+
return `${location}?t=${fileHash}`
137+
} else {
138+
// External url
139+
return `${location}`
140+
}
132141
}).filter((url) => !!url)
133142
this.scripts = this.scripts.concat(userScripts)
134143
}

0 commit comments

Comments
 (0)