-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (24 loc) · 944 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
var url = require('url');
const PostAsset = hexo.model('PostAsset');
/*
* Override asset_img tag function with this function. This function
* does the exact same function as the core asset_img tag, but it also
* allows for url override
*/
hexo.extend.tag.register('asset_img', function(args) {
const assetURL = hexo.config.asset_img_url;
var url = '';
var slug = args.shift();
if (!slug) return;
var asset = PostAsset.findOne({post: this._id, slug: slug});
if (!asset) return;
if (assetURL)
url = assetURL;
// if title is not assigned, set it ''
var title = args.length ? args.join(' ') : '';
// alt always exist
var alt = title || asset.slug;
hexo.log.debug(`[hexo-tag-asset-img] override asset_img generating img tag with url: ${assetURL}${hexo.config.root}${asset.path}`);
return '<img src="' + url + hexo.config.root + asset.path + '" alt="' + alt + '" title="' + title + '">';
});