Skip to content

5.6.0

Latest

Choose a tag to compare

@jerryc127 jerryc127 released this 16 Jul 09:02

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 緩動曲線,取代原本的線性插值
  • rightsideScrollPercentgoUpElement / scrollPercentElement 改為閉包緩存,避免每次滾動都查詢 DOM
  • overflowPaddingRpage-header / menus 元素改為閉包緩存
  • 漢堡選單切換時 document.getElementById 查詢結果緩存到 sidebarFn
  • adjustMenuclassList.toggle 包裹在 requestAnimationFrame
  • forPostFn 改為接收 $article 參數,內部所有函數(addHighlightTooladdPhotoFigcaptionrunLightboxscrollFnToDoaddTableWrapclickFnOfTagHidetabsFn)統一使用傳入的 $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.jstranslateButtonObject 改為 let,支持 pjax 後重新查詢
  • Mermaid 手勢系統重構:用 AbortController 管理事件監聽生命週期,避免重複綁定;wheel 事件加入 stopPropagation 防止穿透滾動;getBoundingClientRect 加入 dirty flag 緩存;DOM 更新改為 requestAnimationFrame 批次處理;deltaMode 正規化處理跨瀏覽器差異
  • Mermaid 圖片預覽 URL 的 revokeObjectURL 超時從 30 秒縮短為 5 秒
  • MathJax 改用 ui/lazy 模組實現延遲渲染,移除原本的 renderActions.findScript hack
  • MathJax 重新渲染改用 typesetClear + typesetPromise,取代 texReset
  • random_cover.jsresolvePostAsset 提取為獨立函數,減少重複邏輯
  • page.jsgetVersion 改為直接引用模組頂部 requirethemeVersion,避免每次呼叫都重複讀取 package.json
  • inject_head_js.js 的 darkmode 判斷邏輯修復了 start > end(跨午夜)的時段判斷錯誤

Bug Fixes

  • 修復 pjax 下簡繁轉換按鈕文字不會更新的問題(translateButtonObject 改為 let 並在 translateInitialization 中重新查詢)
  • 修復 pjax 完成時 script[data-pjax] 替換失敗的問題(加入 item.parentNode 存在性檢查)
  • 修復 pjax 錯誤處理中 responseURL 可能為 undefined 的問題,加入空值檢查
  • 修復 handleThemeChangethemeChange 可能不是物件的問題(加入 typeof fn !== 'function' 檢查)
  • 修復 scrollFncheckDocumentHeight() 在初始化時過早 return 導致滾動事件未綁定的問題
  • 修復 Mermaid 在 Chrome 上滾動時圖表亂跳的問題(svg.style.touchAction = 'none' + wheel 事件 preventDefault + stopPropagation
  • 修復 Mermaid 手勢在 themeChange/pjax 後重複綁定的問題(AbortController 清理 + __mermaidGestureBound 移除改用 __mermaidAbortController
  • 修復 Mermaid 配置解析失敗時無錯誤回報的問題(加入 try/catch)
  • 修復 gallery.jsIMAGE_REGEX 在多次呼叫時 lastIndex 未重置的 bug
  • 修復 flink.jsbutton.js 缺少 HTML escape 導致的 XSS 風險
  • 修復 hide.jsparseArgs 缺少 trim 導致參數帶有前導空格
  • 修復 series.js 模組級可變狀態 groups 在多次 build 時累積過期資料(加入 before_generate 清理)
  • 修復 score.js 重複實現 escapeHTML,改用 hexo-utilescapeHTML + 額外處理 {}
  • 修復 getArchiveLength.jsmonthly 模式下 year 計數未累加的問題(year 計數改為始終執行)
  • 修復 getArchiveLength.js 中 key 選取邏輯,daily 模式下也能正確取得月份計數
  • 修復 related_post.jspostDesc 被提前計算的問題,改為在渲染時才取值
  • 修復 page.jsshuoshuoFN 時區轉換的變數作用域問題
  • 修復 page.jscloudTags 多餘的 colorClass 變數和 class
  • 修復 page.jsfindArchivesTitle 遞迴時 m[key] 可能不是字串的問題
  • 修復 main.jsfetchUrl 在 HTTP 失敗時靜默返回空數組的問題,改為 throw 錯誤
  • 修復 main.jsrunJustifiedGallerylimit / firstLimit 為非法值時的邊界處理
  • 修復 main.jsaddJustifiedGallerydata 非陣列時的錯誤處理
  • 修復 main.jssanitizeString 從只替換 " 改為替換 &"'<> 五種字符
  • 修復 main.jsforPostFnhbe-container 存在時跳過初始化
  • 修復 main.jsgallery 空數據時顯示載入動畫的問題

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
  • adjustMenuhideMenuIndex 改為先宣告再賦值
  • scrollFnisChatBtn 改為 typeof window.chatBtn !== 'undefined'
  • scrollFninnerHeight 改為每次滾動時動態計算 window.innerHeight + 56

New Features

  • Add Knocket chat support with new knocket.pug template and config option
  • Add script and CSS caching mechanism (scriptCache / cssCache) to prevent duplicate loads
  • Add rafThrottle utility function based on requestAnimationFrame
  • Add HTML escape function (sanitizeString) to prevent XSS injection

Performance

  • Replace TOC scroll handling with IntersectionObserver instead of throttle + iteration, significantly reducing scroll event computation
  • Switch scroll handler from btf.throttle to btf.rafThrottle, syncing with browser render frame rate
  • Add rafThrottle to resize event handler
  • Change scrollToDest smooth scrolling from linear interpolation to easeOutQuart easing
  • Cache goUpElement / scrollPercentElement in closure for rightsideScrollPercent, avoiding DOM queries on every scroll
  • Cache page-header / menus elements in closure for overflowPaddingR
  • Cache document.getElementById results in sidebarFn for hamburger menu toggle
  • Wrap adjustMenu's classList.toggle in requestAnimationFrame
  • Refactor forPostFn to accept $article parameter; all internal functions (addHighlightTool, addPhotoFigcaption, runLightbox, scrollFnToDo, addTableWrap, clickFnOfTagHide, tabsFn) use the passed $article instead of repeated document.getElementById('article-container')
  • Convert tabsFn to event delegation, binding click listener on $article instead of each .tabs element
  • Convert clickFnOfTagHide to event delegation, binding on $article instead of individual .hide-button elements
  • Rewrite getActualHeight to use cloneNode(true) + hidden insertion measurement instead of traversing parent nodes and modifying styles
  • Change Traditional/Simplified Chinese lookup from indexOf to Map.has / Map.get for O(1) lookups
  • Defer Chinese character mapping initialization (getMaps) to avoid unnecessary computation
  • Change translateButtonObject in tw_cn.js to let, supporting re-query after pjax
  • Refactor Mermaid gesture system: use AbortController for event listener lifecycle management to prevent duplicate bindings; add stopPropagation to wheel events to prevent scroll pass-through; cache getBoundingClientRect with dirty flag; batch DOM updates via requestAnimationFrame; normalize deltaMode for cross-browser compatibility
  • Reduce Mermaid image preview revokeObjectURL timeout from 30s to 5s
  • Switch MathJax to ui/lazy module for deferred rendering, removing the renderActions.findScript hack
  • Change MathJax re-render to use typesetClear + typesetPromise instead of texReset
  • Extract resolvePostAsset as independent function in random_cover.js to reduce duplication
  • Change getVersion in page.js to reference themeVersion from module-level require, avoiding repeated package.json reads
  • Fix darkmode time range judgment in inject_head_js.js for cross-midnight scenarios (start > end)

Bug Fixes

  • Fix Traditional/Simplified Chinese button text not updating after pjax (translateButtonObject changed to let and re-queried in translateInitialization)
  • Fix script[data-pjax] replacement failure after pjax completion (add item.parentNode existence check)
  • Fix responseURL potentially being undefined in pjax error handling, add null checks
  • Fix handleThemeChange crash when themeChange is not an object (add typeof fn !== 'function' check)
  • Fix scrollFn where checkDocumentHeight() returning early prevented scroll event binding
  • Fix Mermaid chart jumping on scroll in Chrome (svg.style.touchAction = 'none' + preventDefault + stopPropagation on wheel events)
  • Fix Mermaid gesture handlers binding repeatedly after themeChange/pjax (replace __mermaidGestureBound flag with __mermaidAbortController cleanup)
  • Fix Mermaid configuration parse failure with no error feedback (add try/catch)
  • Fix gallery.js IMAGE_REGEX lastIndex not resetting on repeated calls
  • Fix XSS vulnerability in flink.js and button.js due to missing HTML escaping
  • Fix hide.js parseArgs missing trim, causing parameters to have leading spaces
  • Fix series.js module-level mutable groups state accumulating stale data across builds (add before_generate cleanup)
  • Fix score.js duplicating escapeHTML implementation, switch to hexo-util's escapeHTML with additional {} handling
  • Fix getArchiveLength.js year count not accumulating in monthly mode
  • Fix getArchiveLength.js key selection logic so daily mode correctly retrieves month counts
  • Fix related_post.js computing postDesc prematurely; defer to render time
  • Fix page.js timezone variable scope issue in shuoshuoFN
  • Fix page.js cloudTags removing redundant colorClass variable and class
  • Fix page.js findArchivesTitle recursion where m[key] might not be a string
  • Fix main.js fetchUrl silently returning empty array on HTTP failure; now throws error
  • Fix main.js runJustifiedGallery edge case handling when limit / firstLimit are invalid values
  • Fix main.js addJustifiedGallery error handling when data is not an array
  • Fix main.js sanitizeString from only replacing " to replacing &, ", ', <, > characters
  • Fix main.js forPostFn skipping initialization when hbe-container exists
  • Fix main.js gallery 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 Mermaid openSvgInNewTab
  • Set MathJax lazyMargin to 200px
  • Change adjustMenu hideMenuIndex from inline to pre-declared
  • Change scrollFn isChatBtn to typeof window.chatBtn !== 'undefined'
  • Change scrollFn innerHeight to dynamically compute window.innerHeight + 56 on each scroll