Appearance
添加自定义js
注意:要在pjax函数里调用函数,否则不会生效
javascript
function postAddToc () {
let postContent = document.querySelector('#post>#article-container.post-content')
let cardToc = document.getElementById('card-toc')
if (postContent && cardToc) {
let tocNumber = cardToc.getElementsByClassName('toc-number')
let tocLink = cardToc.getElementsByClassName('toc-link')
for (let i = 0; i < tocLink.length; i++) {
document.getElementById(decodeURIComponent(tocLink[i].attributes.href.value).slice(1)).dataset.toc = tocNumber[i].innerText
}
}
}
// 适配pjax
function whenDOMReady() {
postAddToc();
......
}添加自定义css
css
#post #article-container.post-content h1,
#post #article-container.post-content h2,
#post #article-container.post-content h3,
#post #article-container.post-content h4,
#post #article-container.post-content h5,
#post #article-container.post-content h6 {
padding-left: 0 !important;
}
#post #article-container.post-content h1::before,
#post #article-container.post-content h2::before,
#post #article-container.post-content h3::before,
#post #article-container.post-content h4::before,
#post #article-container.post-content h5::before,
#post #article-container.post-content h6::before {
position: relative;
content: attr(data-toc) ' ';
display: inline;
font-family: inherit;
font-size: inherit;
line-height: inherit;
margin-left: 0;
}开启目录配置
yaml
# Post
# --------------------------------------
# toc (目錄)
toc:
post: true
page: false
number: true
expand: false
style_simple: false # for posthexo三连即可
yaml
hexo clean
hexo g
hexo s