Skip to content

Commit

Permalink
fix(image): remove unnecessary hostname check
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Aug 15, 2020
1 parent 539a07b commit 14cc3ed
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const marked = require('marked');
const { encodeURL, slugize, stripHTML, url_for, isExternalLink } = require('hexo-util');
const MarkedRenderer = marked.Renderer;
const { parse } = require('url');
const { sep } = require('path');
let hexo;

Expand Down Expand Up @@ -93,16 +92,15 @@ class Renderer extends MarkedRenderer {
const { relative_link } = hexo.config;
const { options } = this;
const { lazyload, prependRoot, postId } = options;
const { hostname } = parse(href);

if (!hostname && !relative_link && prependRoot) {
if (!relative_link && prependRoot) {
if (postId) {
const PostAsset = hexo.model('PostAsset');
// slug requires platform-specific path
const asset = PostAsset.findOne({ post: postId, slug: href.replace(/\/|\\/g, sep) });
if (asset) href = encodeURL(('/' + asset.path).replace(/\\/g, '/').replace(/\/{2,}/g, '/'));
}
href = url_for.call(options, href);
href = url_for.call(hexo, href);
}

let out = `<img src="${encodeURL(href)}"`;
Expand Down

0 comments on commit 14cc3ed

Please sign in to comment.