Skip to content

添加自定义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 post

hexo三连即可

发表于
更新于
阅读量
yaml
hexo clean
hexo g
hexo s

Released under the MIT License.