Skip to content

Commit e6071f6

Browse files
committed
Merge pull request #325 from jakubrohleder/fix/prefixing-data-urls
PrefixLink fixes
2 parents 364a549 + ecca692 commit e6071f6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/isomorphic/gatsby-helpers.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { config } from 'config'
33
import invariant from 'invariant'
44
import _ from 'lodash'
55

6+
function isDataURL (s) {
7+
// Regex from https://gist.github.com/bgrins/6194623#gistcomment-1671744
8+
// eslint-disable-next-line max-len
9+
const regex = /^\s*data:([a-z]+\/[a-z0-9\-\+]+(;[a-z\-]+=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9!\$&',\(\)\*\+,;=\-\._~:@\/\?%\s]*\s*$/i
10+
return !!s.match(regex)
11+
}
12+
613
// Function to add prefix to links.
714
const prefixLink = (_link) => {
815
if (
@@ -15,7 +22,11 @@ const prefixLink = (_link) => {
1522
`
1623
invariant(_.isString(config.linkPrefix), invariantMessage)
1724

18-
return config.linkPrefix + _link
25+
if (isDataURL(_link)) {
26+
return _link
27+
} else {
28+
return config.linkPrefix + _link
29+
}
1930
} else {
2031
return _link
2132
}

0 commit comments

Comments
 (0)