Skip to content

Commit

Permalink
Merge pull request #3 from chiedo/master
Browse files Browse the repository at this point in the history
Protect the script from failing in weird scenerios
  • Loading branch information
rkazakov authored Mar 16, 2017
2 parents e5ba86b + 3b11806 commit e5dc5ac
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,19 @@ module.exports = function(html, options) {
return '<style amp-custom>' + minified + '</style>';
};

if (src.indexOf('//') === -1) {
path = options.cwd + '/' + src;
if (fs.existsSync(path)) {
file = setFile(String(fs.readFileSync(path)));
}
}
else if (src.indexOf('//') != -1) {
file = setFile(String(request(path).data));
};
try {
if (src.indexOf('//') === -1) {
path = options.cwd + '/' + src;
if (fs.existsSync(path)) {
file = setFile(String(fs.readFileSync(path)));
}
}
else if (src.indexOf('//') != -1) {
file = setFile(String(request(path).data));
};
} catch (err) {
console.dir(err);
}

$(this).replaceWith(file);
});
Expand Down

0 comments on commit e5dc5ac

Please sign in to comment.