From 34a7fdb871cbaf8b54c43a372776469616d7e7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Tue, 4 May 2021 20:40:42 +0800 Subject: [PATCH] =?UTF-8?q?asset:=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8OSS?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=9B=BE=E7=89=87=E3=80=81=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=AD=89=E8=B5=84=E6=BA=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 2 ++ scripts/tag/oss-image.js | 33 +++++++++++++++++++++++++++++++++ scripts/tag/oss-video.js | 26 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 scripts/tag/oss-image.js create mode 100644 scripts/tag/oss-video.js diff --git a/_config.yml b/_config.yml index 365865f..2f12f91 100644 --- a/_config.yml +++ b/_config.yml @@ -175,3 +175,5 @@ plantuml: outputFormat: "svg" sitemap: path: sitemap.xml +oss: + endpoint: https://archgrid-resource.oss-cn-beijing.aliyuncs.com \ No newline at end of file diff --git a/scripts/tag/oss-image.js b/scripts/tag/oss-image.js new file mode 100644 index 0000000..eb01161 --- /dev/null +++ b/scripts/tag/oss-image.js @@ -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 ``; +}); \ No newline at end of file diff --git a/scripts/tag/oss-video.js b/scripts/tag/oss-video.js new file mode 100644 index 0000000..d4d6f0f --- /dev/null +++ b/scripts/tag/oss-video.js @@ -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 ``; +}); \ No newline at end of file