🐛 修復Hexo 5.0.0 以下版本, toc遇到中文不會滾動的bugs close #297, close #299

This commit is contained in:
Jerry 2020-08-07 18:11:26 +08:00
parent 988cbcc331
commit 82979322c6
3 changed files with 8 additions and 1 deletions

View File

@ -88,6 +88,7 @@
script.
var GLOBAL_CONFIG = {
root: '!{config.root}',
hexoversion: '!{get_hexo_version()}',
algolia: !{algolia},
localSearch: !{localSearch},
translate: !{translate},

View File

@ -61,3 +61,7 @@ hexo.extend.helper.register('urlNoIndex', function () {
hexo.extend.helper.register('md5', function (path) {
return crypto.createHash('md5').update(decodeURI(this.url_for(path))).digest('hex')
})
hexo.extend.helper.register('get_hexo_version', function () {
return hexo.version
})

View File

@ -465,6 +465,7 @@ const tocFn = function () {
// DOM Hierarchy:
// ol.toc > (li.toc-item, ...)
// li.toc-item > (a.toc-link, ol.toc-2child > (li.toc-item, ...))
const versionBiggerFive = GLOBAL_CONFIG.hexoversion.split('.')[0] >= 5
const findHeadPosition = function (top) {
// assume that we are not in the post page if no TOC link be found,
// thus no need to update the status
@ -477,7 +478,8 @@ const tocFn = function () {
list.each(function () {
const head = $(this)
if (top > head.offset().top - 25) {
currentId = '#' + encodeURI($(this).attr('id'))
if (versionBiggerFive) currentId = '#' + encodeURI($(this).attr('id'))
else currentId = '#' + $(this).attr('id')
}
})