5.6.0
Full Changelog: 5.5.5...5.6.0
New Features
- 新增 Knocket 聊天功能,新增對應的 pug 模板
knocket.pug,在聊天配置中新增knocket選項 - 新增腳本和樣式表緩存機制(
scriptCache/cssCache),避免重複加載相同資源 - 新增
rafThrottle工具函數,基於requestAnimationFrame實現節流 - 新增 HTML 轉義函數(
sanitizeString),防範 XSS 注入
Performance
- TOC 滾動改用
IntersectionObserver取代原本的 throttle + 遍歷方式,大幅減少滾動事件計算量 - 滾動處理從
btf.throttle改為btf.rafThrottle,與瀏覽器渲染幀率同步 resize事件處理加入rafThrottle節流scrollToDest平滑滾動改用 easeOutQuart 緩動曲線,取代原本的線性插值rightsideScrollPercent的goUpElement/scrollPercentElement改為閉包緩存,避免每次滾動都查詢 DOMoverflowPaddingR的page-header/menus元素改為閉包緩存- 漢堡選單切換時
document.getElementById查詢結果緩存到sidebarFn adjustMenu的classList.toggle包裹在requestAnimationFrame中forPostFn改為接收$article參數,內部所有函數(addHighlightTool、addPhotoFigcaption、runLightbox、scrollFnToDo、addTableWrap、clickFnOfTagHide、tabsFn)統一使用傳入的$article查詢,避免重複document.getElementById('article-container')tabsFn改為事件委託,將點擊監聽綁在$article上而非每個.tabs元素clickFnOfTagHide改為事件委託,綁在$article上而非逐個.hide-button綁定getActualHeight改用cloneNode(true)+ 隱藏插入測量,取代原本遍歷父節點修改style的方式- 簡繁轉換的查找從
indexOf改為Map.has/Map.get,O(1) 查找 - 簡繁字對映改為延遲初始化(
getMaps),避免不必要的計算 tw_cn.js的translateButtonObject改為let,支持 pjax 後重新查詢- Mermaid 手勢系統重構:用
AbortController管理事件監聽生命週期,避免重複綁定;wheel 事件加入stopPropagation防止穿透滾動;getBoundingClientRect加入 dirty flag 緩存;DOM 更新改為requestAnimationFrame批次處理;deltaMode正規化處理跨瀏覽器差異 - Mermaid 圖片預覽 URL 的
revokeObjectURL超時從 30 秒縮短為 5 秒 - MathJax 改用
ui/lazy模組實現延遲渲染,移除原本的renderActions.findScripthack - MathJax 重新渲染改用
typesetClear+typesetPromise,取代texReset random_cover.js的resolvePostAsset提取為獨立函數,減少重複邏輯page.js的getVersion改為直接引用模組頂部require的themeVersion,避免每次呼叫都重複讀取package.jsoninject_head_js.js的 darkmode 判斷邏輯修復了start > end(跨午夜)的時段判斷錯誤
Bug Fixes
- 修復 pjax 下簡繁轉換按鈕文字不會更新的問題(
translateButtonObject改為let並在translateInitialization中重新查詢) - 修復 pjax 完成時
script[data-pjax]替換失敗的問題(加入item.parentNode存在性檢查) - 修復 pjax 錯誤處理中
responseURL可能為undefined的問題,加入空值檢查 - 修復
handleThemeChange中themeChange可能不是物件的問題(加入typeof fn !== 'function'檢查) - 修復
scrollFn中checkDocumentHeight()在初始化時過早 return 導致滾動事件未綁定的問題 - 修復 Mermaid 在 Chrome 上滾動時圖表亂跳的問題(
svg.style.touchAction = 'none'+ wheel 事件preventDefault+stopPropagation) - 修復 Mermaid 手勢在 themeChange/pjax 後重複綁定的問題(AbortController 清理 +
__mermaidGestureBound移除改用__mermaidAbortController) - 修復 Mermaid 配置解析失敗時無錯誤回報的問題(加入 try/catch)
- 修復
gallery.js的IMAGE_REGEX在多次呼叫時lastIndex未重置的 bug - 修復
flink.js和button.js缺少 HTML escape 導致的 XSS 風險 - 修復
hide.js的parseArgs缺少 trim 導致參數帶有前導空格 - 修復
series.js模組級可變狀態groups在多次 build 時累積過期資料(加入before_generate清理) - 修復
score.js重複實現 escapeHTML,改用hexo-util的escapeHTML+ 額外處理{} - 修復
getArchiveLength.js中monthly模式下 year 計數未累加的問題(year 計數改為始終執行) - 修復
getArchiveLength.js中 key 選取邏輯,daily模式下也能正確取得月份計數 - 修復
related_post.js中postDesc被提前計算的問題,改為在渲染時才取值 - 修復
page.js中shuoshuoFN時區轉換的變數作用域問題 - 修復
page.js中cloudTags多餘的colorClass變數和 class - 修復
page.js中findArchivesTitle遞迴時m[key]可能不是字串的問題 - 修復
main.js的fetchUrl在 HTTP 失敗時靜默返回空數組的問題,改為 throw 錯誤 - 修復
main.js的runJustifiedGallery在limit/firstLimit為非法值時的邊界處理 - 修復
main.js的addJustifiedGallery在data非陣列時的錯誤處理 - 修復
main.js的sanitizeString從只替換"改為替換&、"、'、<、>五種字符 - 修復
main.js的forPostFn在hbe-container存在時跳過初始化 - 修復
main.js的gallery空數據時顯示載入動畫的問題
Changed
- Mermaid 手勢縮放從固定倍率(1.1/0.9)改為連續倍率(
Math.pow(1.001, delta)),操作更平滑 - Mermaid 手勢的 viewBox 範圍限制從每次計算改為預計算
minW/maxW/minH/maxH - Mermaid
openSvgInNewTab移除了不再需要的typeof svg === 'string'分支 - MathJax 的
lazyMargin設為200px adjustMenu的hideMenuIndex改為先宣告再賦值scrollFn的isChatBtn改為typeof window.chatBtn !== 'undefined'scrollFn的innerHeight改為每次滾動時動態計算window.innerHeight + 56
New Features
- Add Knocket chat support with new
knocket.pugtemplate and config option - Add script and CSS caching mechanism (
scriptCache/cssCache) to prevent duplicate loads - Add
rafThrottleutility function based onrequestAnimationFrame - Add HTML escape function (
sanitizeString) to prevent XSS injection
Performance
- Replace TOC scroll handling with
IntersectionObserverinstead of throttle + iteration, significantly reducing scroll event computation - Switch scroll handler from
btf.throttletobtf.rafThrottle, syncing with browser render frame rate - Add
rafThrottletoresizeevent handler - Change
scrollToDestsmooth scrolling from linear interpolation to easeOutQuart easing - Cache
goUpElement/scrollPercentElementin closure forrightsideScrollPercent, avoiding DOM queries on every scroll - Cache
page-header/menuselements in closure foroverflowPaddingR - Cache
document.getElementByIdresults insidebarFnfor hamburger menu toggle - Wrap
adjustMenu'sclassList.toggleinrequestAnimationFrame - Refactor
forPostFnto accept$articleparameter; all internal functions (addHighlightTool,addPhotoFigcaption,runLightbox,scrollFnToDo,addTableWrap,clickFnOfTagHide,tabsFn) use the passed$articleinstead of repeateddocument.getElementById('article-container') - Convert
tabsFnto event delegation, binding click listener on$articleinstead of each.tabselement - Convert
clickFnOfTagHideto event delegation, binding on$articleinstead of individual.hide-buttonelements - Rewrite
getActualHeightto usecloneNode(true)+ hidden insertion measurement instead of traversing parent nodes and modifying styles - Change Traditional/Simplified Chinese lookup from
indexOftoMap.has/Map.getfor O(1) lookups - Defer Chinese character mapping initialization (
getMaps) to avoid unnecessary computation - Change
translateButtonObjectintw_cn.jstolet, supporting re-query after pjax - Refactor Mermaid gesture system: use
AbortControllerfor event listener lifecycle management to prevent duplicate bindings; addstopPropagationto wheel events to prevent scroll pass-through; cachegetBoundingClientRectwith dirty flag; batch DOM updates viarequestAnimationFrame; normalizedeltaModefor cross-browser compatibility - Reduce Mermaid image preview
revokeObjectURLtimeout from 30s to 5s - Switch MathJax to
ui/lazymodule for deferred rendering, removing therenderActions.findScripthack - Change MathJax re-render to use
typesetClear+typesetPromiseinstead oftexReset - Extract
resolvePostAssetas independent function inrandom_cover.jsto reduce duplication - Change
getVersioninpage.jsto referencethemeVersionfrom module-levelrequire, avoiding repeatedpackage.jsonreads - Fix darkmode time range judgment in
inject_head_js.jsfor cross-midnight scenarios (start > end)
Bug Fixes
- Fix Traditional/Simplified Chinese button text not updating after pjax (
translateButtonObjectchanged toletand re-queried intranslateInitialization) - Fix
script[data-pjax]replacement failure after pjax completion (additem.parentNodeexistence check) - Fix
responseURLpotentially beingundefinedin pjax error handling, add null checks - Fix
handleThemeChangecrash whenthemeChangeis not an object (addtypeof fn !== 'function'check) - Fix
scrollFnwherecheckDocumentHeight()returning early prevented scroll event binding - Fix Mermaid chart jumping on scroll in Chrome (
svg.style.touchAction = 'none'+preventDefault+stopPropagationon wheel events) - Fix Mermaid gesture handlers binding repeatedly after themeChange/pjax (replace
__mermaidGestureBoundflag with__mermaidAbortControllercleanup) - Fix Mermaid configuration parse failure with no error feedback (add try/catch)
- Fix
gallery.jsIMAGE_REGEXlastIndexnot resetting on repeated calls - Fix XSS vulnerability in
flink.jsandbutton.jsdue to missing HTML escaping - Fix
hide.jsparseArgsmissing trim, causing parameters to have leading spaces - Fix
series.jsmodule-level mutablegroupsstate accumulating stale data across builds (addbefore_generatecleanup) - Fix
score.jsduplicatingescapeHTMLimplementation, switch tohexo-util'sescapeHTMLwith additional{}handling - Fix
getArchiveLength.jsyear count not accumulating inmonthlymode - Fix
getArchiveLength.jskey selection logic sodailymode correctly retrieves month counts - Fix
related_post.jscomputingpostDescprematurely; defer to render time - Fix
page.jstimezone variable scope issue inshuoshuoFN - Fix
page.jscloudTagsremoving redundantcolorClassvariable and class - Fix
page.jsfindArchivesTitlerecursion wherem[key]might not be a string - Fix
main.jsfetchUrlsilently returning empty array on HTTP failure; now throws error - Fix
main.jsrunJustifiedGalleryedge case handling whenlimit/firstLimitare invalid values - Fix
main.jsaddJustifiedGalleryerror handling whendatais not an array - Fix
main.jssanitizeStringfrom only replacing"to replacing&,",',<,>characters - Fix
main.jsforPostFnskipping initialization whenhbe-containerexists - Fix
main.jsgallery showing loading animation when data is empty
Changed
- Mermaid gesture zoom from fixed factor (1.1/0.9) to continuous factor (
Math.pow(1.001, delta)) for smoother operation - Mermaid gesture viewBox bounds from computed on each move to pre-calculated
minW/maxW/minH/maxH - Remove unnecessary
typeof svg === 'string'branch in MermaidopenSvgInNewTab - Set MathJax
lazyMarginto200px - Change
adjustMenuhideMenuIndexfrom inline to pre-declared - Change
scrollFnisChatBtntotypeof window.chatBtn !== 'undefined' - Change
scrollFninnerHeightto dynamically computewindow.innerHeight + 56on each scroll