32 lines
766 B
JavaScript
32 lines
766 B
JavaScript
hexo.extend.tag.register('oss_image', function(args) {
|
|
let { config } = hexo;
|
|
|
|
let requestImage = args.shift() || '';
|
|
if (requestImage.length === 0) {
|
|
return '';
|
|
}
|
|
let imageSrc = `${config.oss.endpoint}/${requestImage}`;
|
|
|
|
let attrs = [];
|
|
attrs.push(`src="${imageSrc}"`);
|
|
|
|
let altMessage = args.shift() || '';
|
|
attrs.push(`alt="${altMessage}"`);
|
|
|
|
let width = args.shift() || 0;
|
|
if (width !== 0) {
|
|
attrs.push(`width="${width}"`);
|
|
}
|
|
|
|
let height = args.shift() || 0;
|
|
if (height !== 0) {
|
|
attrs.push(`height="${height}"`);
|
|
}
|
|
|
|
let classes = args.shift() || '';
|
|
if (classes.length !== 0) {
|
|
attrs.push(`class="${classes}"`);
|
|
}
|
|
|
|
return `<img ${attrs.join(" ")} />`;
|
|
}); |