asset:支持使用OSS保存图片、视频等资源。
This commit is contained in:
parent
a0109c28ae
commit
34a7fdb871
|
@ -175,3 +175,5 @@ plantuml:
|
|||
outputFormat: "svg"
|
||||
sitemap:
|
||||
path: sitemap.xml
|
||||
oss:
|
||||
endpoint: https://archgrid-resource.oss-cn-beijing.aliyuncs.com
|
33
scripts/tag/oss-image.js
Normal file
33
scripts/tag/oss-image.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
hexo.extend.tag.register('oss_image', function(args) {
|
||||
let { config } = hexo;
|
||||
|
||||
let requestImage = args[0] || '';
|
||||
let versionCode = args[1] || '';
|
||||
if (requestImage.length === 0 || versionCode.length === 0) {
|
||||
return '';
|
||||
}
|
||||
let imageSrc = `${config.oss.endpoint}/${requestImage}?versionId=${versionCode}`;
|
||||
|
||||
let attrs = [];
|
||||
attrs.push(`src="${imageSrc}"`);
|
||||
|
||||
let altMessage = args[2] || '';
|
||||
attrs.push(`alt="${altMessage}"`);
|
||||
|
||||
let classes = args[3] || '';
|
||||
if (classes.length !== 0) {
|
||||
attrs.push(`class="${classes}"`);
|
||||
}
|
||||
|
||||
let width = args[4] || 0;
|
||||
if (width !== 0) {
|
||||
attrs.push(`width="${width}"`);
|
||||
}
|
||||
|
||||
let height = args[5] || 0;
|
||||
if (height !== 0) {
|
||||
attrs.push(`height="${height}"`);
|
||||
}
|
||||
|
||||
return `<img ${attrs.join(" ")} />`;
|
||||
});
|
26
scripts/tag/oss-video.js
Normal file
26
scripts/tag/oss-video.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
hexo.extend.tag.register('oss_video', function(args) {
|
||||
let { config } = hexo;
|
||||
|
||||
let src = args[0] || '';
|
||||
let versionId = args[1] || '';
|
||||
if (src.length === 0 || versionId.length === 0) {
|
||||
return '';
|
||||
}
|
||||
let fullUrl = `${config.oss.endpoint}/${src}?versionId=${versionId}`;
|
||||
let affix = src.substring(src.lastIndexOf('.') + 1);
|
||||
|
||||
let attrs = []
|
||||
attrs.push('controls');
|
||||
attrs.push('muted="true"');
|
||||
|
||||
let width = args[2] || 0;
|
||||
let height = args[3] || 0;
|
||||
if (width !== 0) {
|
||||
attrs.push(`width="${width}"`);
|
||||
}
|
||||
if (height !== 0) {
|
||||
attrs.push(`height="${height}"`);
|
||||
}
|
||||
|
||||
return `<video ${attrs.join(' ')}><source src="${fullUrl}"} type="video/${affix}"></video>`;
|
||||
});
|
Loading…
Reference in New Issue
Block a user