From f483f3f7f2c007297b4059710e105aaf545520b7 Mon Sep 17 00:00:00 2001 From: "1152958806@qq.com" <17683872107czx> Date: Wed, 30 Aug 2023 15:42:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96toc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/assets/js/main.js | 24 ++++++++++++++ templates/assets/zhheo/blogex.js | 8 ----- templates/modules/common/toc-bot.html | 46 --------------------------- 3 files changed, 24 insertions(+), 54 deletions(-) diff --git a/templates/assets/js/main.js b/templates/assets/js/main.js index 39aed8b7..fd42b62e 100644 --- a/templates/assets/js/main.js +++ b/templates/assets/js/main.js @@ -147,6 +147,29 @@ document.addEventListener('DOMContentLoaded', function () { } } + /** + * toc + */ + const tocFn = function () { + const postContent = document.querySelector('.post-content'); + + if (postContent == null) return; + + const headers = postContent.querySelectorAll('h1,h2,h3,h4,h5,h6'); + // 没有 toc 目录,则直接移除 + if (headers.length === 0) { + document.getElementById("card-toc").remove(); + } else { + tocbot.init({ + tocSelector: '.toc-content', + contentSelector: '.post-content', + headingSelector: 'h1,h2,h3,h4,h5,h6', + hasInnerContainers: true + }); + + } + } + /** * 滾動處理 */ @@ -446,6 +469,7 @@ document.addEventListener('DOMContentLoaded', function () { if (GLOBAL_CONFIG.isPost) { addRuntime(); + tocFn(); } else { addLastPushDate() toggleCardCategory() diff --git a/templates/assets/zhheo/blogex.js b/templates/assets/zhheo/blogex.js index f61e78c8..b23d7675 100644 --- a/templates/assets/zhheo/blogex.js +++ b/templates/assets/zhheo/blogex.js @@ -452,13 +452,6 @@ function removeLoading() { }, 3000) } -//移除pwa -navigator.serviceWorker.getRegistrations().then(function (registrations) { - for (let registration of registrations) { - registration.unregister() - } -}) - function addFriendLink() { var input = document.getElementsByClassName('el-textarea__inner')[0]; let evt = document.createEvent('HTMLEvents'); @@ -672,7 +665,6 @@ function initBlog() { //隐藏加载动画 GLOBAL_CONFIG.loadingBox && heo.hideLoading(), checkUrlAndAddHideBanner() - } // 如果当前页有评论就执行函数 diff --git a/templates/modules/common/toc-bot.html b/templates/modules/common/toc-bot.html index d961bd06..6e925230 100644 --- a/templates/modules/common/toc-bot.html +++ b/templates/modules/common/toc-bot.html @@ -4,51 +4,5 @@ - - - - - \ No newline at end of file From cbad8adb0aeaac91ba0ee397dc1929e8e9dc3435 Mon Sep 17 00:00:00 2001 From: "1152958806@qq.com" <17683872107czx> Date: Wed, 30 Aug 2023 17:28:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?flink=20=E5=8F=8B=E9=93=BE=E6=A0=87?= =?UTF-8?q?=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/assets/js/custom.js | 90 +++++++++++++++++++++++++++++++ templates/assets/zhheo/custom.css | 9 ++++ 2 files changed, 99 insertions(+) diff --git a/templates/assets/js/custom.js b/templates/assets/js/custom.js index 84956cbf..53cb9972 100644 --- a/templates/assets/js/custom.js +++ b/templates/assets/js/custom.js @@ -428,6 +428,96 @@ document.addEventListener("DOMContentLoaded", () => { } ); + + // flink 友链标签 + customElements.define( + "hao-flink", + class HaoGalleryGroup extends HTMLElement { + constructor() { + super(); + this.options = { + name: this.getAttribute("name"), + desc: this.getAttribute("desc"), + style: this.getAttribute("style"), + }; + const _temp = getChildren(this, "_tpl"); + let _innerHTML = _temp.innerHTML.trim().replace(/^(
)|(
)$/g, ""); + let style = this.options.style; + let content = ""; + let contents = ""; + let class_desc = ""; + _innerHTML.replace( + /{([^}]*)}/g, + function ($0, $1) { + var flink = $1.split(",",5); + if(style=='beautify'){ + contents +=` +
+ + ${flink[0]} + + + +
+ ${flink[0]} +
+
+ ${flink[0]} + ${flink[3]} +
+
+
+ ` + } + if(style=='default'){ + contents +=` + + ` + } + } + + ); + if(this.options.desc!=null && this.options.desc!=''){ + class_desc =` + + ` + } + if(this.options.style=='beautify'){ + content =` +
+ ${contents} +
+ ` + } + if(this.options.style=='default'){ + content =` + + ` + } + let htmlStr = ` +
+ + ${class_desc} + ${content} +
+ `; + this.innerHTML = htmlStr; + } + } + ); + + customElements.define( "hao-dplayer", class HaoDplayer extends HTMLElement { diff --git a/templates/assets/zhheo/custom.css b/templates/assets/zhheo/custom.css index 81c69319..1a8760eb 100644 --- a/templates/assets/zhheo/custom.css +++ b/templates/assets/zhheo/custom.css @@ -2102,4 +2102,13 @@ p.p.purple,span.p.purple { p.p.gray,span.p.gray { color: #999 +} + +.flink-name { + margin-bottom: 5px; + font-weight: 700; + font-size: 1.5em +} +.flink-desc { + margin: .2rem 0 .5rem } \ No newline at end of file