From 8e49532406cb5c4d71584e8562f12afd71f9b263 Mon Sep 17 00:00:00 2001 From: jiewenhuang Date: Sat, 12 Aug 2023 19:17:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E9=A1=B5=E9=9D=A2=EF=BC=88=E6=96=87=E7=AB=A0=EF=BC=8C?= =?UTF-8?q?=E7=95=99=E8=A8=80=E6=9D=BF=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- annotation-setting.yaml | 150 ++++++++++++- templates/assets/js/leaving.js | 277 ++++++++---------------- templates/assets/js/min/leaving.min.js | 2 +- templates/modules/pageMetaVariable.html | 24 ++ templates/page.html | 105 ++++++++- templates/page_leaving.html | 107 +++++++++ 6 files changed, 473 insertions(+), 192 deletions(-) create mode 100644 templates/modules/pageMetaVariable.html create mode 100644 templates/page_leaving.html diff --git a/annotation-setting.yaml b/annotation-setting.yaml index 6403f04..afddf03 100644 --- a/annotation-setting.yaml +++ b/annotation-setting.yaml @@ -157,4 +157,152 @@ spec: formSchema: - $formkit: "text" name: "icon" - label: "图标" \ No newline at end of file + label: "图标" + +--- + +apiVersion: v1alpha1 +kind: AnnotationSetting +metadata: + generateName: annotation-setting- +spec: + targetRef: + group: content.halo.run + kind: SinglePage + formSchema: + - $formkit: "select" + name: "enable_aside" + label: "是否启用侧边栏" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_page_meta" + label: "是否展示页面元信息(即顶部的字数、阅读量等数据)" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_passage_tips" + label: "是否展示温馨提示" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_collect_check" + label: "是否启用百度收录检查" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_read_limit" + label: "是否开启评论后可见" + value: "false" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "use_raw_content" + label: "是否渲染原始内容" + value: "false" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_comment" + label: "是否启用评论功能" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_toc" + label: "是否启用 Toc 目录" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "text" + name: "toc_depth" + label: "Toc 目录默认展开层级 0~6,对应标题层级 h1 ~ h6" + value: "0" + - $formkit: "text" + name: "img_max_width" + label: "图片最大宽度" + value: "100%" + - $formkit: "select" + name: "img_align" + label: "图片对齐方式" + value: "center" + options: + - value: "center" + label: 居中 + - value: "left" + label: 左对齐 + - value: "right" + label: 右对齐 + - $formkit: "select" + name: "enable_copy" + label: "是否允许复制内容" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_donate" + label: "是否启用打赏(必须配置好相应二维码)" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_share" + label: "是否启用分享" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_like" + label: "是否启用点赞" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 + - $formkit: "select" + name: "enable_fold_long_code" + label: "是否开启长代码块自动折叠" + value: "true" + options: + - value: "true" + label: 是 + - value: "false" + label: 否 \ No newline at end of file diff --git a/templates/assets/js/leaving.js b/templates/assets/js/leaving.js index 67f267e..f3c63cd 100644 --- a/templates/assets/js/leaving.js +++ b/templates/assets/js/leaving.js @@ -1,184 +1,93 @@ -/**留言页逻辑 */ -const leavingContext = { - /* 获取留言板数据 */ - getData() { - const sheetId = $(".joe_detail__title").attr("data-sheetid"); - const $leavingList = $(".joe_leaving-list"); - const $leavingNone = $(".joe_leaving-none"); - const $leavingLoading = $(".joe_loading"); - - Utils.request({ - url: `/api/content/sheets/${sheetId}/comments/top_view`, - method: "GET", - data: { - page: 0, - // size: ThemeConfig_leaving_card_max, - sort: "createTime,desc", - }, - }) - .then((res) => { - if (res.total) { - const str = res.content.reduce((sum, item) => { - if (item.content.trim()) { - // 渲染留言中的 emoji - const markedHtml = marked(item.content) - .replace(/]*>/gm, "[图片内容]") - .replace(/bili\//g, "bili/hd/ic_emoji_"); - const emoji = Utils.renderedEmojiHtml(markedHtml); - item.content = Utils.return2Br(emoji); - } - const avatar = `${ - ThemeConfig_gravatar_source || ThemeConfig_gravatar_source_url - }/${item.gravatarMd5}?s=256&d=${ThemeConfig_gravatar_type}`; - return (sum += `
  • -
    - 用户头像 -
    ${item.author}
    -
    ${new Date( - item.createTime - ).toLocaleDateString()}
    -
    -
    -
    ${item.content}
    -
    -
  • `); - }, ""); - $leavingList.html(str); - leavingContext.randomColor(); - } else { - $leavingList.hide(); - $leavingNone.show(); - } - $leavingLoading && $leavingLoading.hide(); - }) - .catch((_err) => { - $leavingLoading && $leavingLoading.hide(); - $leavingList.hide(); - $leavingNone.show(); - }); - }, - // /* 设置标题 */ - // setTitleText() { - // if ( - // !ThemeConfig_leaving_title || - // ThemeConfig_leaving_title.trim() === "留言板" - // ) - // return; - // $(".joe_detail__title").text(ThemeConfig_leaving_title); - // }, - /* 设置无数据文案 */ - setEmptyText() { - if ( - !$(".joe_leaving-none.tpl").length || - !ThemeConfig_leaving_empty_text || - ThemeConfig_leaving_empty_text.trim() === "暂无留言,期待第一个脚印。" - ) - return; - $(".joe_leaving-none").text(ThemeConfig_leaving_empty_text); - }, - /* 随机样式 */ - randomColor() { - let _index = 100; - const colors = [ - "#dcc10c", - "#299bec", - "#ea5455", - "#7367f0", - "#32ccbb", - "#f6416c", - "#28c76f", - "#9f44d3", - "#f55555", - "#736efe", - "#e96d71", - "#de4313", - "#d939cd", - "#4c83ff", - "#f072b6", - "#c346c2", - "#5961f9", - "#fd6585", - "#465efb", - "#ffc600", - "#fa742b", - "#5151e5", - "#bb4e75", - "#e255cd", - "#63c549", - "#0ecdde", - "#f067b4", - "#f067b4", - "#ff9a9e", - "#1dd5de", - "#4facfe", - "#f093fb", - "#6fa3ef", - "#bc99c4", - "#46c47c", - "#f9bb3c", - "#e8583d", - "#f68e5f", - ]; - const random = (min, max) => - Math.floor(Math.random() * (max - min + 1)) + min; - const $el = $(".joe_leaving-list"); - const maxWidth = $el.width(); - const maxHeight = $el.height(); - const radius1 = [ - "20px 300px", - "20px 400px", - "20px 500px", - "30px 300px", - "30px 400px", - "30px 500px", - "40px 300px", - "40px 400px", - "40px 500px", - ]; - const radius2 = [ - "300px 20px", - "400px 20px", - "500px 20px", - "300px 30px", - "400px 30px", - "500px 30px", - "300px 40px", - "400px 40px", - "500px 40px", - ]; - $(".joe_leaving-list .item").each((index, item) => { - const zIndex = random(1, 99); - const background = colors[random(0, colors.length - 1)]; - const width = Math.ceil($(item).width()); - const height = Math.ceil($(item).height()); - const top = random(0, maxHeight - height); - const left = random(0, maxWidth - width); - $(item).css({ - display: "block", - zIndex, - background, - top, - left, - borderTopLeftRadius: radius2[random(0, radius2.length - 1)], - borderTopRightRadius: radius1[random(0, radius1.length - 1)], - borderBottomLeftRadius: radius1[random(0, radius1.length - 1)], - borderBottomRightRadius: radius1[random(0, radius1.length - 1)], - }); - $(item).draggabilly({ containment: true }); - $(item).on("dragStart", (e) => { - _index++; - $(item).css({ zIndex: _index }); - }); - }); - }, -}; - -document.addEventListener("DOMContentLoaded", () => { - // leavingContext.setTitleText(); - leavingContext.setEmptyText(); - leavingContext.getData(); -}); +/* 随机样式 */ +let _index = 100; +const colors = [ + "#dcc10c", + "#299bec", + "#ea5455", + "#7367f0", + "#32ccbb", + "#f6416c", + "#28c76f", + "#9f44d3", + "#f55555", + "#736efe", + "#e96d71", + "#de4313", + "#d939cd", + "#4c83ff", + "#f072b6", + "#c346c2", + "#5961f9", + "#fd6585", + "#465efb", + "#ffc600", + "#fa742b", + "#5151e5", + "#bb4e75", + "#e255cd", + "#63c549", + "#0ecdde", + "#f067b4", + "#f067b4", + "#ff9a9e", + "#1dd5de", + "#4facfe", + "#f093fb", + "#6fa3ef", + "#bc99c4", + "#46c47c", + "#f9bb3c", + "#e8583d", + "#f68e5f", +]; // 定义你的颜色数组 +const random = (min, max) => + Math.floor(Math.random() * (max - min + 1)) + min; +const $el = $(".joe_leaving-list"); +const maxWidth = $el.width(); +const maxHeight = $el.height(); +const radius1 = [ + "20px 300px", + "20px 400px", + "20px 500px", + "30px 300px", + "30px 400px", + "30px 500px", + "40px 300px", + "40px 400px", + "40px 500px", +]; +const radius2 = [ + "300px 20px", + "400px 20px", + "500px 20px", + "300px 30px", + "400px 30px", + "500px 30px", + "300px 40px", + "400px 40px", + "500px 40px", +]; +$(".joe_leaving-list .item").each((index, item) => { + const zIndex = random(1, 99); + const background = colors[random(0, colors.length - 1)]; + const width = Math.ceil($(item).width()); + const height = Math.ceil($(item).height()); + const top = random(0, maxHeight - height); + const left = random(0, maxWidth - width); + $(item).css({ + display: "block", + zIndex, + background, + top, + left, + borderTopLeftRadius: radius2[random(0, radius2.length - 1)], + borderTopRightRadius: radius1[random(0, radius1.length - 1)], + borderBottomLeftRadius: radius1[random(0, radius1.length - 1)], + borderBottomRightRadius: radius1[random(0, radius1.length - 1)], + }); + $(item).draggabilly({ containment: true }); + $(item).on("dragStart", (e) => { + _index++; + $(item).css({ zIndex: _index }); + }); +}); \ No newline at end of file diff --git a/templates/assets/js/min/leaving.min.js b/templates/assets/js/min/leaving.min.js index 2331306..02f7bc0 100644 --- a/templates/assets/js/min/leaving.min.js +++ b/templates/assets/js/min/leaving.min.js @@ -1 +1 @@ -(()=>{var o={getData:function(){var e=$(".joe_detail__title").attr("data-sheetid"),t=$(".joe_leaving-list"),a=$(".joe_leaving-none"),n=$(".joe_loading");Utils.request({url:"/api/content/sheets/".concat(e,"/comments/top_view"),method:"GET",data:{page:0,sort:"createTime,desc"}}).then(function(e){e.total?(e=e.content.reduce(function(e,t){t.content.trim()&&(a=marked(t.content).replace(/]*>/gm,"[图片内容]").replace(/bili\//g,"bili/hd/ic_emoji_"),a=Utils.renderedEmojiHtml(a),t.content=Utils.return2Br(a));var a="".concat(ThemeConfig_gravatar_source||ThemeConfig_gravatar_source_url,"/").concat(t.gravatarMd5,"?s=256&d=").concat(ThemeConfig_gravatar_type);return e+'
  • \n
    \n 用户头像\n
    ').concat(t.author,'
    \n
    ').concat(new Date(t.createTime).toLocaleDateString(),'
    \n
    \n
    \n
    ').concat(t.content,"
    \n
    \n
  • ")},""),t.html(e),o.randomColor()):(t.hide(),a.show()),n&&n.hide()}).catch(function(e){n&&n.hide(),t.hide(),a.show()})},setEmptyText:function(){$(".joe_leaving-none.tpl").length&&ThemeConfig_leaving_empty_text&&"暂无留言,期待第一个脚印。"!==ThemeConfig_leaving_empty_text.trim()&&$(".joe_leaving-none").text(ThemeConfig_leaving_empty_text)},randomColor:function(){function i(e,t){return Math.floor(Math.random()*(t-e+1))+e}var r=100,d=["#dcc10c","#299bec","#ea5455","#7367f0","#32ccbb","#f6416c","#28c76f","#9f44d3","#f55555","#736efe","#e96d71","#de4313","#d939cd","#4c83ff","#f072b6","#c346c2","#5961f9","#fd6585","#465efb","#ffc600","#fa742b","#5151e5","#bb4e75","#e255cd","#63c549","#0ecdde","#f067b4","#f067b4","#ff9a9e","#1dd5de","#4facfe","#f093fb","#6fa3ef","#bc99c4","#46c47c","#f9bb3c","#e8583d","#f68e5f"],e=$(".joe_leaving-list"),l=e.width(),p=e.height(),f=["20px 300px","20px 400px","20px 500px","30px 300px","30px 400px","30px 500px","40px 300px","40px 400px","40px 500px"],s=["300px 20px","400px 20px","500px 20px","300px 30px","400px 30px","500px 30px","300px 40px","400px 40px","500px 40px"];$(".joe_leaving-list .item").each(function(e,t){var a=i(1,99),n=d[i(0,d.length-1)],o=Math.ceil($(t).width()),c=Math.ceil($(t).height()),c=i(0,p-c),o=i(0,l-o);$(t).css({display:"block",zIndex:a,background:n,top:c,left:o,borderTopLeftRadius:s[i(0,s.length-1)],borderTopRightRadius:f[i(0,f.length-1)],borderBottomLeftRadius:f[i(0,f.length-1)],borderBottomRightRadius:f[i(0,f.length-1)]}),$(t).draggabilly({containment:!0}),$(t).on("dragStart",function(e){r++,$(t).css({zIndex:r})})})}};document.addEventListener("DOMContentLoaded",function(){o.setEmptyText(),o.getData()})})(); \ No newline at end of file +let _index=100;const colors=["#dcc10c","#299bec","#ea5455","#7367f0","#32ccbb","#f6416c","#28c76f","#9f44d3","#f55555","#736efe","#e96d71","#de4313","#d939cd","#4c83ff","#f072b6","#c346c2","#5961f9","#fd6585","#465efb","#ffc600","#fa742b","#5151e5","#bb4e75","#e255cd","#63c549","#0ecdde","#f067b4","#f067b4","#ff9a9e","#1dd5de","#4facfe","#f093fb","#6fa3ef","#bc99c4","#46c47c","#f9bb3c","#e8583d","#f68e5f"],random=(d,e)=>Math.floor(Math.random()*(e-d+1))+d,$el=$(".joe_leaving-list"),maxWidth=$el.width(),maxHeight=$el.height(),radius1=["20px 300px","20px 400px","20px 500px","30px 300px","30px 400px","30px 500px","40px 300px","40px 400px","40px 500px"],radius2=["300px 20px","400px 20px","500px 20px","300px 30px","400px 30px","500px 30px","300px 40px","400px 40px","500px 40px"];$(".joe_leaving-list .item").each((d,e)=>{var a=random(1,99),x=colors[random(0,colors.length-1)],p=Math.ceil($(e).width()),i=Math.ceil($(e).height()),i=random(0,maxHeight-i),p=random(0,maxWidth-p);$(e).css({display:"block",zIndex:a,background:x,top:i,left:p,borderTopLeftRadius:radius2[random(0,radius2.length-1)],borderTopRightRadius:radius1[random(0,radius1.length-1)],borderBottomLeftRadius:radius1[random(0,radius1.length-1)],borderBottomRightRadius:radius1[random(0,radius1.length-1)]}),$(e).draggabilly({containment:!0}),$(e).on("dragStart",d=>{_index++,$(e).css({zIndex:_index})})}); \ No newline at end of file diff --git a/templates/modules/pageMetaVariable.html b/templates/modules/pageMetaVariable.html new file mode 100644 index 0000000..a05ac54 --- /dev/null +++ b/templates/modules/pageMetaVariable.html @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/templates/page.html b/templates/page.html index 2c43ad4..9532722 100644 --- a/templates/page.html +++ b/templates/page.html @@ -1,10 +1,103 @@ - - -

    -
    + + +
    + +
    +
    +
    +

    [[${singlePage.spec.title}]]

    + +
    +
    + + +
    + +
    + [[${#dates.format(singlePage.spec.publishTime,'yyyy-MM-dd')}]] + / + [[${singlePage.stats.comment}]] 评论 + / + [[${singlePage.stats.visit}]] 阅读 + / + + [[${wordCount}]] 字 + + + / + 正在检测是否收录... + +
    + +
    + +
    + +
    +
    + +
    +
    + + + + + +
    [[${singlePage.content.content}]]
    +
    +
    +
    + + + +
    + +
    + +
    + +
    + + + + 博主关闭了当前页面的评论 +
    +
    + + + +
    +
    + +
    +
    + + + + 博主关闭了所有页面的评论 +
    +
    +
    +
    + + + + +
    + + + +
    + + diff --git a/templates/page_leaving.html b/templates/page_leaving.html new file mode 100644 index 0000000..1d9b1fb --- /dev/null +++ b/templates/page_leaving.html @@ -0,0 +1,107 @@ + + + + +
    + +
    +
    +
    + +

    [[${singlePage.spec.title}]]

    + +
    +
    + + +
    + +
    + [[${#dates.format(singlePage.spec.publishTime,'yyyy-MM-dd')}]] + / + [[${singlePage.stats.comment}]] 评论 + / + [[${singlePage.stats.visit}]] 阅读 + / + + [[${wordCount}]] 字 + + + / + 正在检测是否收录... + +
    + +
    + +
    + +
    +
    +
    +
    +
      +
    • +
      + 用户头像 +
      +
      +
      +
      +
      +
      +
    • + +
    + +
    暂无留言,期待第一个脚印。
    +
    +
    +
    + +
    + +
    + + + + 博主关闭了当前页面的评论 +
    +
    + + + +
    +
    + +
    +
    + + + + 博主关闭了所有页面的评论 +
    +
    +
    +
    + + + +
    + + +
    + + [[${singlePage.metadata.name}]] + + + + \ No newline at end of file