From 5f733646cc05b9f30088e3586707c4ae36e39b62 Mon Sep 17 00:00:00 2001 From: i-abc <104631897+i-abc@users.noreply.github.com> Date: Thu, 12 Jan 2023 14:00:56 +0800 Subject: [PATCH] =?UTF-8?q?Waline=20=E6=96=B0=E5=A2=9E=E5=9B=BE=E5=BA=8A?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8F=AF=E9=80=89=E9=A1=B9=20(#237)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 20 +++++++++++++++++++ .../plugins/comments/waline/script.ejs | 17 ++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/_config.yml b/_config.yml index 53c7ee2..93c6065 100755 --- a/_config.yml +++ b/_config.yml @@ -148,6 +148,26 @@ comments: # - https://unpkg.com/@waline/emojis@1.1.0/tieba # - https://unpkg.com/@waline/emojis@1.1.0/tw-emoji # - https://unpkg.com/@waline/emojis@1.1.0/bmoji + # 设置自己的图床服务,替换默认的 Base 64 编码嵌入(有体积大小限制),在评论中上传图片更加方便 + # imageUploader: + # 适配了兰空图床V1、V2版本 + # 以兰空图床V1为例,下列填写内容为: + # fileName: file + # tokenName: Authorization + # url: https://xxxxxx/api/v1/upload + # token: Bearer xxxxxxxxxxxxxx + # resp: data.links.url + # 以兰空图床V2为例,下列填写内容为: + # fileName: image + # tokenName: token + # url: https://xxxxxx/api/upload + # token: xxxxxxxxxxxxxx + # resp: data.url + # fileName: # 根据版本二选一 + # tokenName: # 根据版本二选一 + # api: # 图床 api 地址 + # token: # 图床验证 + # resp: # 图片地址返回值的字段 # Artalk # https://artalk.js.org/ diff --git a/layout/_partial/plugins/comments/waline/script.ejs b/layout/_partial/plugins/comments/waline/script.ejs index d20eb9c..aed62b8 100644 --- a/layout/_partial/plugins/comments/waline/script.ejs +++ b/layout/_partial/plugins/comments/waline/script.ejs @@ -11,6 +11,23 @@ Waline.init(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, { el: '#waline_container', path: path, + <% if(!!theme.comments.waline.imageUploader?.api){ %> + imageUploader: function(file) { + let headers = new Headers(); + headers.set('Accept', 'application/json'); + <% if(!!theme.comments.waline.imageUploader?.token) { %> + headers.set('<%= theme.comments.waline.imageUploader?.tokenName %>', '<%= theme.comments.waline.imageUploader?.token %>') + <% } %> + let formData = new FormData(); + formData.append('<%= theme.comments.waline.imageUploader?.fileName %>', file); + return fetch('<%= theme.comments.waline.imageUploader?.api %>',{ + method: 'POST', + body: formData, + headers: headers + }).then((resp) => resp.json()) + .then((resp) => resp.<%= theme.comments.waline.imageUploader?.resp %>) + }, + <% } %> })); }); }