增加自定义页面

This commit is contained in:
liuzhihang 2022-10-14 21:29:05 +08:00
parent a9bb1d08b3
commit ecfef9543c
3 changed files with 577 additions and 54 deletions

View File

@ -1,13 +1,16 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<th:block th:with="postItems=${posts.items}" th:fragment="post-list">
<th:block th:fragment="post-list" th:with="postItems=${posts.items}">
<!-- card需要添加在没有图片时使用随机图片 -->
<div class="recent-post-item lastestpost-item" th:each="post : ${postItems}">
<div class="post_cover left_radius">
<a th:attr="title=${post.spec.title}" th:href="${post.status.permalink}">
<img class="post_bg" th:alt="${post.spec.title}" th:attr="data-lazy-src=${post.spec.cover}">
<a th:attr="title=${post.spec.title}" th:href="${post.status.permalink}" data-pjax-state>
<img class="post_bg entered loaded"
th:alt="${post.status.excerpt}"
th:attr="data-lazy-src=${post.spec.cover}"
th:src="${post.spec.cover}">
</a>
</div>
<!-- 类别非空时 -->

View File

@ -1,4 +1,523 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width,initial-scale=1" name="viewport">
<title th:text="${site.title}"></title>
<meta content="telephone=no" name="format-detection">
<meta content="var(--heo-card-bg)" name="theme-color">
<script th:src="@{/assets/js/heo.js}"></script>
<link rel="stylesheet" th:href="@{/assets/zhheo/zhheoblog.css}">
<!-- fontawesome-pro https://github.com/duyplus/fontawesome-pro -->
<link href="https://cdn.jsdelivr.net/gh/duyplus/fontawesome-pro/css/all.min.css"
media="print"
onload='this.media="all"'
rel="stylesheet"
/>
<!-- 右下角通知 -->
<link href="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/node-snackbar/0.1.16/snackbar.min.css"
media="print"
onload='this.media="all"'
rel="stylesheet"
/>
<script>var GLOBAL_CONFIG = {
root: "/",
algolia: {
appId: "29APOGIOTD",
apiKey: "49d70d2ba6e9c2a001a1c8737785d7ee",
indexName: "Heo",
hits: {per_page: 10},
languages: {
input_placeholder: "输入关键词快速查找",
hits_empty: "找不到你查询的内容:${query}",
hits_stats: "找到 ${hits} 条结果,用时 ${time} 毫秒"
}
},
localSearch: void 0,
translate: {defaultEncoding: 2, translateDelay: 0, msgToTraditionalChinese: "简", msgToSimplifiedChinese: "繁"},
noticeOutdate: void 0,
highlight: {plugin: "highlighjs", highlightCopy: !0, highlightLang: !0, highlightHeightLimit: 400},
copy: {success: "复制成功", error: "复制错误", noSupport: "浏览器不支持"},
relativeDate: {homepage: !0, post: !1},
runtime: "天",
date_suffix: {just: "刚刚", min: "分钟前", hour: "小时前", day: "天前", month: "个月前"},
copyright: void 0,
lightbox: "fancybox",
Snackbar: {
chs_to_cht: "你已切换为繁体",
cht_to_chs: "你已切换为简体",
day_to_night: "你已切换为深色模式",
night_to_day: "你已切换为浅色模式",
bgLight: "#49b1f5",
bgDark: "#121212",
position: "top-center"
},
source: {
jQuery: "https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js",
justifiedGallery: {
js: "https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js",
css: "https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/justifiedGallery/3.8.1/css/justifiedGallery.min.css"
},
fancybox: {
js: "https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/fancybox/3.5.7/jquery.fancybox.min.js",
css: "https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/fancybox/3.5.7/jquery.fancybox.min.css"
}
},
isPhotoFigcaption: !0,
islazyload: !0,
isanchor: !1
}</script>
<script id="config-diff">var GLOBAL_CONFIG_SITE = {
title: "版权协议",
isPost: !1,
isHome: !1,
isHighlightShrink: !1,
isToc: !1,
postUpdate: "2020-07-22 22:06:17"
}</script>
<noscript>
<style>#nav {
opacity: 1
}
.justified-gallery img {
opacity: 1
}
#post-meta time, #recent-posts time {
display: inline !important
}</style>
</noscript>
<script>(win => {
win.saveToLocal = {
set: function setWithExpiry(key, value, ttl) {
if (ttl === 0) return
const now = new Date()
const expiryDay = ttl * 86400000
const item = {
value: value,
expiry: now.getTime() + expiryDay,
}
localStorage.setItem(key, JSON.stringify(item))
},
get: function getWithExpiry(key) {
const itemStr = localStorage.getItem(key)
if (!itemStr) {
return undefined
}
const item = JSON.parse(itemStr)
const now = new Date()
if (now.getTime() > item.expiry) {
localStorage.removeItem(key)
return undefined
}
return item.value
}
}
win.getScript = url => new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = true
script.onerror = reject
script.onload = script.onreadystatechange = function () {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
script.onload = script.onreadystatechange = null
resolve()
}
document.head.appendChild(script)
})
win.activateDarkMode = function () {
document.documentElement.setAttribute('data-theme', 'dark')
heo.initThemeColor()
}
win.activateLightMode = function () {
document.documentElement.setAttribute('data-theme', 'light')
heo.initThemeColor()
}
const t = saveToLocal.get('theme')
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
if (t === undefined) {
if (isLightMode) activateLightMode()
else if (isDarkMode) activateDarkMode()
else if (isNotSpecified || hasNoSupport) {
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 6 || hour >= 18
isNight ? activateDarkMode() : activateLightMode()
}
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
if (saveToLocal.get('theme') === undefined) {
e.matches ? activateDarkMode() : activateLightMode()
}
})
} else if (t === 'light') activateLightMode()
else activateDarkMode()
const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
if (asideStatus === 'hide') {
document.documentElement.classList.add('hide-aside')
} else {
document.documentElement.classList.remove('hide-aside')
}
}
})(window)</script>
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js"></script>
<link href="https://at.alicdn.com/t/font_1891866_47sukspu18q.css" rel="stylesheet">
<link href="https://cdn2.tianli0.top/npm/remixicon@2.5.0/fonts/remixicon.css" rel="stylesheet">
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/Swiper/8.0.6/swiper-bundle.min.css" rel="stylesheet">
<link rel="stylesheet" th:href="@{/assets/zhheo/commentBarrage.css}">
<script data-pace-options='{ "restartOnRequestAfter":false,"eventLag":false}'
src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/pace/1.2.4/pace.min.js"></script>
</head>
<body>
<!-- loading 页面 -->
<div id="loading-box" onclick="heo.hideLoading()">
<div class="loading-bg"><img class="loading-img" src="https://img.zhheo.com/i/2022/08/31/630f01a3755aa.webp"></div>
</div>
<div id="web_bg"></div>
<!-- 控制台 -->
<div th:replace="modules/widgets/console :: console"></div>
<div class="page" id="body-wrap">
<header class="not-top-img" id="page-header">
<nav th:replace="modules/nav :: nav"></nav>
</header>
<main class="layout hide-aside" id="content-inner">
<div id="page">
<div id="article-container" th:utext="${singlePage.content.content}"></div>
</div>
</main>
<!-- 底部 -->
<footer th:replace="modules/footer :: footer"></footer>
</div>
<div id="rightside">
<div id="rightside-config-hide">
<button id="translateLink" title="简繁转换" type="button"></button>
<button id="darkmode" title="浅色和深色模式转换" type="button"><i class="fas fa-adjust"></i></button>
</div>
<div id="rightside-config-show">
<button id="rightside_config" title="设置" type="button"><i class="fas fa-cog fa-spin"></i></button>
<button id="go-up" title="回到顶部" type="button"><i class="fas fa-arrow-up"></i></button>
</div>
</div>
<div id="algolia-search">
<div class="search-dialog">
<div class="search-dialog__title" id="algolia-search-title">搜索</div>
<div id="algolia-input-panel">
<div id="algolia-search-input"></div>
</div>
<div id="algolia-search-results">
<div id="algolia-hits"><a class="tag-list" href="../tags/%E7%83%AD%E9%97%A8/index.html">热门</a><a
class="tag-list" href="../tags/Hexo/index.html">Hexo</a><a class="tag-list"
href="../tags/Sketch/index.html">Sketch</a><a
class="tag-list" href="../tags/%E8%AE%BE%E8%AE%A1/index.html">设计</a><a class="tag-list"
href="../tags/%E6%95%99%E7%A8%8B/index.html">教程</a>
</div>
<div id="algolia-pagination"></div>
<div id="algolia-stats"></div>
</div>
<div id="algolia-tips"><i class="fa-brands fa-algolia"></i><span
class="algolia-tips-text">Algolia 提供搜索服务</span></div>
<span class="search-close-button"><i class="fas fa-times"></i></span></div>
<div id="search-mask"></div>
</div>
<div class="js-pjax">
<div id="rightMenu">
<div class="rightMenu-group rightMenu-small">
<div class="rightMenu-item" id="menu-backward"><i class="fa-solid fa-arrow-left"></i></div>
<div class="rightMenu-item" id="menu-forward"><i class="fa-solid fa-arrow-right"></i></div>
<div class="rightMenu-item" id="menu-refresh"><i class="fa-solid fa-arrow-rotate-right"></i></div>
<div class="rightMenu-item" id="menu-top"><i class="fa-solid fa-arrow-up"></i></div>
</div>
<div class="rightMenu-group rightMenu-line rightMenuPlugin">
<div class="rightMenu-item" id="menu-copytext"><i class="fa-duotone fa-copy"></i><span>复制选中文本</span>
</div>
<div class="rightMenu-item" id="menu-pastetext"><i class="fa-duotone fa-paste"></i><span>粘贴文本</span>
</div>
<a class="rightMenu-item" id="menu-commenttext"><i
class="fa-duotone fa-comment-medical"></i><span>引用到评论</span></a>
<div class="rightMenu-item" id="menu-newwindow"><i
class="fa-duotone fa-window-restore"></i><span>新窗口打开</span></div>
<div class="rightMenu-item" id="menu-copylink"><i
class="fa-duotone fa-link-horizontal"></i><span>复制链接地址</span></div>
<div class="rightMenu-item" id="menu-copyimg"><i class="fa-duotone fa-images"></i><span>复制此图片</span>
</div>
<div class="rightMenu-item" id="menu-downloadimg"><i
class="fa-duotone fa-download"></i><span>下载此图片</span></div>
<div class="rightMenu-item" id="menu-search"><i
class="fa-solid fa-magnifying-glass"></i><span>站内搜索</span></div>
<div class="rightMenu-item" id="menu-searchBaidu"><i
class="fa-solid fa-magnifying-glass"></i><span>百度搜索</span></div>
<div class="rightMenu-item" id="menu-music-toggle"><i class="fas fa-play"></i><span>播放音乐</span></div>
<div class="rightMenu-item" id="menu-music-back"><i
class="fa-duotone fa-backward"></i><span>切换到上一首</span></div>
<div class="rightMenu-item" id="menu-music-forward"><i
class="fa-duotone fa-forward"></i><span>切换到下一首</span></div>
<div class="rightMenu-item" id="menu-music-playlist"
onclick='window.open("https://music.163.com/#/playlist?app_version=8.8.36&amp;id=5197802668","_blank")'>
<i class="fa-duotone fa-list-music"></i><span>查看所有歌曲</span></div>
<div class="rightMenu-item" id="menu-music-copyMusicName"><i class="fa-duotone fa-copy"></i>
<span>复制歌名</span></div>
</div>
<div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link"
id="menu-randomPost"><i
class="fa-duotone fa-dice"></i><span>随便逛逛</span></a><a class="rightMenu-item menu-link"
href="../categories/index.html"><i
class="fa-duotone fa-list-tree"></i><span>博客分类</span></a><a class="rightMenu-item menu-link"
href="../tags/index.html"><i
class="fa-duotone fa-tags"></i><span>文章标签</span></a></div>
<div class="rightMenu-group rightMenu-line"><a class="rightMenu-item menu-link" href="index.html"><i
class="fa-solid fa-hand"></i><span>隐私协议</span></a><a class="rightMenu-item menu-link"
href="index.html"><i
class="fa-solid fa-closed-captioning"></i><span>版权协议</span></a></div>
<div class="rightMenu-group rightMenu-line rightMenuOther">
<div class="rightMenu-item" id="menu-copy"><i
class="fa-duotone fa-link-horizontal"></i><span>复制地址</span></div>
<div class="rightMenu-item" id="menu-commentBarrage"><i class="fa-solid fa-message-captions"></i><span
class="menu-commentBarrage-text">关闭热评</span></div>
<div class="rightMenu-item" id="menu-darkmode"><i class="fa-solid fa-moon"></i><span
class="menu-darkmode-text">显示模式</span></div>
<div class="rightMenu-item" id="menu-translate"><i class="fa-duotone fa-language"></i><span>轉為繁體</span>
</div>
</div>
</div>
<div id="rightmenu-mask"></div>
</div>
<div>
<script th:src="@{/assets/js/utils.js}"></script>
<script th:src="@{/assets/js/main.js}"></script>
<script charset="utf-8" data-pjax="" th:src="@{/assets/zhheo/blogex.js}"></script>
<script src="https://cdn.zhheo.com/JS-Heo/translate/tw_cn.js"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/instant.page/5.1.0/instantpage.min.js"
type="module"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vanilla-lazyload/17.3.1/lazyload.iife.min.js"></script>
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/node-snackbar/0.1.16/snackbar.min.js"></script>
<script defer src="https://cdn.zhheo.com/public/algolia/algolia.js"></script>
<script>var preloader = {
endLoading: () => {
//- document.body.style.overflow = 'auto';
document.getElementById('loading-box').classList.add("loaded")
},
initLoading: () => {
//- document.body.style.overflow = '';
document.getElementById('loading-box').classList.remove("loaded")
}
}
window.addEventListener('load', preloader.endLoading())
setTimeout(function () {
preloader.endLoading();
}, 3000)</script>
<div class="js-pjax"></div>
<script>window.addEventListener('load', () => {
const changeContent = (content) => {
if (content === '') return content
content = content.replace(/<img.*?src="(.*?)"?[^\>]+>/ig, '[图片]') // replace image link
content = content.replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, '[链接]') // replace url
content = content.replace(/<pre><code>.*?<\/pre>/gi, '[代码]') // replace code
content = content.replace(/<[^>]+>/g, "") // remove html tag
if (content.length > 150) {
content = content.substring(0, 150) + '...'
}
return content
}
const getComment = () => {
const runTwikoo = () => {
twikoo.getRecentComments({
envId: 'https://twikoo.zhheo.com',
region: '',
pageSize: 6,
includeReply: true
}).then(function (res) {
const twikooArray = res.map(e => {
return {
'content': changeContent(e.comment),
'avatar': e.avatar,
'nick': e.nick,
'url': e.url + '#' + e.id,
'date': new Date(e.created).toISOString()
}
})
saveToLocal.set('twikoo-newest-comments', JSON.stringify(twikooArray), 10 / (60 * 24))
generateHtml(twikooArray)
}).catch(function (err) {
const $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML = "无法获取评论,请确认相关配置是否正确"
})
}
if (typeof twikoo === 'object') {
runTwikoo()
} else {
getScript('https://cdn2.tianli0.top/npm/twikoo@1.6.5/dist/twikoo.all.min.js').then(runTwikoo)
}
}
const generateHtml = array => {
let result = ''
if (array.length) {
for (let i = 0; i < array.length; i++) {
result += '<div class=\'aside-list-item\'>'
if (true) {
const name = 'data-lazy-src'
result += `<a href='${array[i].url}' class='thumbnail'><img ${name}='${array[i].avatar}' alt='${array[i].nick}'><div class='name'><span>${array[i].nick}</span></div></a>`
}
result += `<div class='content'>
<a class='comment' href='${array[i].url}'>${array[i].content}</a>
<time datetime="${array[i].date}">${btf.diffDate(array[i].date, true)}</time></div>
</div>`
}
} else {
result += '没有评论'
}
let $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML = result
window.lazyLoadInstance && window.lazyLoadInstance.update()
window.pjax && window.pjax.refresh($dom)
}
const newestCommentInit = () => {
if (document.querySelector('#card-newest-comments .aside-list')) {
const data = saveToLocal.get('twikoo-newest-comments')
if (data) {
generateHtml(JSON.parse(data))
} else {
getComment()
}
}
}
newestCommentInit()
document.addEventListener('pjax:complete', newestCommentInit)
})</script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/qrcodejs/1.0.0/qrcode.min.js"></script>
<script data-pjax=""
src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/Swiper/6.6.2/swiper-bundle.min.js"></script>
<script th:src="@{/assets/zhheo/rightmenu.js}"></script>
<script th:src="@{/assets/zhheo/random.js}"></script>
<script data-pjax th:src="@{/zhheo/commentBarrage.js}"></script>
<script src="https://cdn.zhheo.com/public/waterfall/waterfall.min.js"></script>
<script src="https://cdn.zhheo.com/public/assist/assist-entry.min.js"></script>
<link href="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/aplayer/1.10.1/APlayer.min.css" media="print"
onload='this.media="all"' rel="stylesheet">
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/aplayer/1.10.1/APlayer.min.js"></script>
<script src="https://cdn.zhheo.com/public/aplayer/Meting2.min.js"></script>
<script src="https://cdn.zhheo.com/public/pjax/pjax.min.js"></script>
<script>let pjaxSelectors = [
'title',
'#config-diff',
'#body-wrap',
'#rightside-config-hide',
'#rightside-config-show',
'.js-pjax'
]
if (false) {
pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
}
var pjax = new Pjax({
elements: 'a:not([target="_blank"])',
selectors: pjaxSelectors,
cacheBust: false,
analytics: false,
scrollRestoration: false
})
document.addEventListener('pjax:send', function () {
// removeEventListener toc scroll
window.removeEventListener('scroll', window.tocScrollFn)
typeof preloader === 'object' && preloader.initLoading()
if (window.aplayers) {
for (let i = 0; i < window.aplayers.length; i++) {
if (!window.aplayers[i].options.fixed) {
window.aplayers[i].destroy()
}
}
}
typeof typed === 'object' && typed.destroy()
//reset readmode
const $bodyClassList = document.body.classList
$bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')
})
document.addEventListener('pjax:complete', function () {
window.refreshFn()
document.querySelectorAll('script[data-pjax]').forEach(item => {
const newScript = document.createElement('script')
const content = item.text || item.textContent || item.innerHTML || ""
Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
newScript.appendChild(document.createTextNode(content))
item.parentNode.replaceChild(newScript, item)
})
GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()
typeof chatBtnFn === 'function' && chatBtnFn()
typeof panguInit === 'function' && panguInit()
// google analytics
typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});
// baidu analytics
typeof _hmt === 'object' && _hmt.push(['_trackPageview', window.location.pathname]);
typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()
// Analytics
if (false) {
MtaH5.pgv()
}
// prismjs
typeof Prism === 'object' && Prism.highlightAll()
typeof preloader === 'object' && preloader.endLoading()
})
document.addEventListener('pjax:error', (e) => {
if (e.request.status === 404) {
pjax.loadUrl('/404.html')
}
})</script>
<script>!function () {
var d = document.createElement("script");
d.src = "https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?b6b512a6a0006dd6fcb565df2b0da0b748a4d749e4d1f2212c129ca4a479426dfd9a9dcb5ced4d7780eb6f3bbd089073c2a6d54440560d63862bbf4ec01bba3a", d.id = "ttzz";
var e = document.getElementsByTagName("script")[0];
e.parentNode.insertBefore(d, e)
}(window)</script>
<script async data-pjax src="../../busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
</div>
<div class="js-pjax">
<script>coverColor(), removeLoading(), addRightMenuClickEvent(), navTitle(), heo.topPostScroll(), heo.topCategoriesBarScroll(), heo.sayhi(), heo.addTag(), heo.stopImgRightDrag(), heo.addFriendLinksInFooter(), heo.qrcodeCreate(), heo.hidecookie(), heo.onlyHome(), heo.addNavBackgroundInit(), heo.initIndexEssay(), heo.changeTimeInEssay(), heo.reflashEssayWaterFall(), heo.addMediumInEssay(), heo.darkModeStatus(), heo.categoriesBarActive(), heo.initThemeColor()</script>
</div>
</body>
</html>

View File

@ -8,43 +8,44 @@
<meta content="telephone=no" name="format-detection">
<meta content="var(--heo-main)" name="theme-color">
<script th:src="@{/assets/js/heo.js}"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
<script script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.5.0/tocbot.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.5.0/tocbot.css">
<script>
//目录使用tocbot来生成
window.addEventListener('load', () => {
var headerEl = 'h1,h2,h3,h4,h5,h6', // headers
content = '.post-content', // 文章容器
idArr = {};
$(content).children(headerEl).each(function () { // 去除空格以及多余标点
var headerId = $(this).text().replace(/[\s|\~|`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\+|\=|\||\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?|\|\|\。]/g, '');
<link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/default.min.css" rel="stylesheet">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
<script crossorigin="anonymous" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ="
script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.5.0/tocbot.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.5.0/tocbot.css" rel="stylesheet">
<script>
//目录使用tocbot来生成
window.addEventListener('load', () => {
var headerEl = 'h1,h2,h3,h4,h5,h6', // headers
content = '.post-content', // 文章容器
idArr = {};
$(content).children(headerEl).each(function () { // 去除空格以及多余标点
var headerId = $(this).text().replace(/[\s|\~|`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\_|\+|\=|\||\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?|\|\|\。]/g, '');
headerId = headerId.toLowerCase();
if (idArr[headerId]) { // id已经存在
$(this).attr('id', headerId + '-' + idArr[headerId]);
idArr[headerId]++;
} else { // id未存在
idArr[headerId] = 1;
$(this).attr('id', headerId);
}
});
tocbot.init({
// 添加到哪里
tocSelector: '.toc-item toc-level',
// 针对那个id标签
contentSelector: content,
// 滚动跟随
positionFixedClass: 'is-position-fixed',
positionFixedSelector: '.toc',
// 需要解析的标题
headingSelector: headerEl
headerId = headerId.toLowerCase();
if (idArr[headerId]) { // id已经存在
$(this).attr('id', headerId + '-' + idArr[headerId]);
idArr[headerId]++;
} else { // id未存在
idArr[headerId] = 1;
$(this).attr('id', headerId);
}
});
tocbot.init({
// 添加到哪里
tocSelector: '.toc-item toc-level',
// 针对那个id标签
contentSelector: content,
// 滚动跟随
positionFixedClass: 'is-position-fixed',
positionFixedSelector: '.toc',
// 需要解析的标题
headingSelector: headerEl
});
}
</script>
});
});
</script>
<link rel="stylesheet" th:href="@{/assets/zhheo/zhheoblog.css}">
<!-- fontawesome-pro https://github.com/duyplus/fontawesome-pro -->
<link href="https://cdn.jsdelivr.net/gh/duyplus/fontawesome-pro/css/all.min.css"
@ -437,7 +438,8 @@
<div class="post-meta__tag-list">
<a class="post-meta__tags" th:each="tag : ${post.tags}" th:href="${tag.status.permalink}">
<span class="tags-punctuation">#</span>
<th:block th:title="${tag.spec.displayName}"></th:block>
<th:block th:title="${tag.spec.displayName}"
th:text="${tag.spec.displayName}"></th:block>
<span class="tagsPageCount" th:text="${tag.status.postCount}"></span>
</a>
</div>
@ -445,23 +447,28 @@
</div>
</div>
<!-- 版权生命 -->
<!-- 版权声明 -->
<div class="post-copyright">
<div class="post-copyright__author">
<!-- 版权页 以及版权描述文字 -->
<a class="post-copyright__original" href="../cc/index.html"
<a class="post-copyright__original" th:href="@{/cc}"
title="该文章为原创文章,注意版权协议">原创</a>
<a class="post-copyright-title" href="#"><span th:text="${post.spec.title}"></span></a>
</div>
<div class="post-copyright__type"><span class="post-copyright-info" id="post-copyright-url"><a
href="1abe0c7.html">https://blog.zhheo.com/p/1abe0c7.html</a></span>
<button class="post-copyright-copybtn" onclick="rm.copyPageUrl()"><i
class="fas fa-paste copy-btn"></i></button>
<div class="post-copyright__type">
<span class="post-copyright-info" id="post-copyright-url">
<a href="javascript:window.location.href;">
text
</a>
</span>
<button class="post-copyright-copybtn" onclick="rm.copyPageUrl()">
<i class="fas fa-paste copy-btn"></i>
</button>
</div>
<div class="post-copyright__notice">
<span class="post-copyright-info">
本文是原创文章,采用 <a href="../cc/index.html" target="_blank">CC BY-NC-ND 4.0</a> 协议,完整转载请注明来自 <a
href="../index.html" target="_blank" th:text="${site.title}"></a>
本文是原创文章,采用 <a th:href="@{/cc}" target="_blank">CC BY-NC-ND 4.0</a> 协议,完整转载请注明来自 <a
href="/" target="_blank" th:text="${site.title}"></a>
</span>
</div>
</div>
@ -832,12 +839,6 @@
typeof chatBtnFn === 'function' && chatBtnFn()
typeof panguInit === 'function' && panguInit()
// Analytics
if (false) {
MtaH5.pgv()
}
// prismjs
typeof Prism === 'object' && Prism.highlightAll()