Hexo 5.0.0 版本發佈

Hexo 是一個基於 Node.js 的靜態網站產生器。它提供強大的 API 來整合現有的 npm 套件以進行網頁開發,並以程式化的方式將特定內容插入文章中。

這是我們迄今為止最大的一次發佈,包含了大量的新功能、效能改進和錯誤修復。根據我們的基準測試(我們在每次 pull request 中都會執行以檢測效能衰退),Hexo 5 在 16 秒內處理了 500 篇文章,而 4.2.0 同時處理 300 篇文章。Hexo 現在需要 Node.js 10+,Node.js 已於 2019 年 12 月 31 日停止支援版本 8;雖然仍然支援 Node.js 10.x,但由於它將在不到一年的時間內(2021 年 4 月)被棄用,我們建議使用 Node.js 12+。

請參考我們的安裝指南來安裝 Hexo。

要升級到 Hexo v5,請在您的 package.json 中變更以下行:

package.json
-  "hexo": "^4.2.1",
+ "hexo": "^5.0.0",

重大變更

  • refactor(external_link): 在 load_config 期間遷移設定 @SukkaW #4414 #4371

    • 請參閱撰寫章節以了解新選項(在 v4 中引入)
    _config.yml
    # Deprecated
    external_link: true|false

    # New option
    external_link:
    enable: true|false

    # Deprecated
    use_date_for_updated: true

    # New option
    # https://hexo.dev.org.tw/docs/configuration#Date-Time-format
    updated_option: date
    • 如果您檢查 external_linktruthy 值,由於它現在會自動轉換為物件,它將永遠是 truthy。
    <% if (config.external_link) { %>
    • 如果您希望保持與過去版本的向後相容性
    <% if ((typeof config.external_link === 'boolean' && config.external_link === true) || (typeof config.external_link === 'object' && config.external_link.enable === true)) { %>
  • refactor(box): 移除 Bluebird.asCallback @SukkaW #4379

    • Box 的回呼語法從未在文件中提及,也從未在 Hexo 內部使用。
    • 這也是一個提醒,我們可能會在未來從所有 Hexo API 中移除回呼。#3328
  • feat: 啟用 config.updated_option @SukkaW #4278

    • 這對於偏好僅在文章的前言(front-matter)中設定時才顯示 Updated: 的主題很有用。
  • feat(open_graph): 從前言中移除 'keywords' 選項 @curbengh #4174

    • 搜尋引擎不再支援 keywords
  • fix: 使用文章的前言覆蓋網站的永久連結 @SukkaW #4359

    • 使用者設定
    _config.yml
    permalink: :year/:month/:day/:title/
    • 前言
    source/foo-bar.md
    ---
    title: foo bar
    permalink: breaking-news/
    ---
    • 該文章將在 http://yourhexo.com/breaking-news/ 上提供
    • 提醒:永久連結必須具有結尾的 .html/
    permalink: :year/:month/:day/:title/ # default
    # or
    permalink: :year/:month/:day/:title.html
  • 從全域變數中移除 lodash @SukkaW #4266

    • Lodash _ 不再在 Hexo API 中可用。
    // Dropped
    <% const arrayB = _.uniq(arrayA) %>
    • 我們鼓勵使用原生的 JS API 而不是 Lodash,我們發現 此指南 很有幫助。
    • 如果您偏好使用 Lodash,您可以隨時安裝它並透過 Helper API 使其可用
  • chore/ci: 移除 Node.js 8 並新增 Node.js 14 @SukkaW #4255

    • Node 8 已於 2019 年 12 月 31 日達到 EOL
  • refactor: 從主題設定中移除網站設定 @SukkaW #4145

    • 先前 hexo.theme.config 會合併到 hexo.config 中,現在它們已分開,以避免設定中可能發生的衝突。

新功能

  • feat(tag): 顯示錯誤的來源 & 美化 @SukkaW #4420

  • feat(post_link): 當無法找到文章時,顯示更好的錯誤訊息 #4426

    • 當檔案名稱不正確時,錯誤訊息現在更清楚。
  • 略過未發佈文章的資源,如果存在則刪除它們 @DaemondShu #3489

    • 當有未發佈的文章時
    ---
    title: Still a draft....
    published: false
    ---
    • 該文章及其資源將不會產生到 public/ 資料夾中。
  • feat(extend/injector): 啟用新的擴充 Injector @SukkaW #4049

    • 請參閱 API 文件以了解用法。
  • feat: 新增 Prism 程式碼高亮支援 @SukkaW #4119

    • 請參閱文件以了解用法。
  • feat(tagcloud): 新增選項 class & level @stevenjoezhang #4370

    • 能夠新增 CSS 樣式的類別名稱。
  • feat(config): 在處理文章前驗證設定 @SukkaW #4381

  • feat(post_permalink): 為文章永久連結新增 :second 屬性選項 @kkocdko #4185

    • 範例
    permalink: :year/:month/:day/:hour/:minute/:second/:title.html
  • feat(youtube_tag): 新增 cookie 選項 @curbengh #4155

    • 停用時,cookie 不會在 YouTube 影片嵌入中設定/傳送。
  • feat(youtube_tag): 支援播放清單 @SukkaW #4139

    • 能夠嵌入播放清單。
  • feat(load_theme_config): 支援替代主題設定 @SukkaW #4120

    • 主題可以在檔案 _config.[name].yml 中設定,例如 hexo-theme-landscape_config.landscape.yml
    • 將檔案放在根資料夾中,與目前的 _config.yml 相同。
    • 請參閱文件以了解設定優先順序。
  • feat(feed_tag): 支援剖析 config.feed @curbengh #4029

  • feat(tag): 新增 unregister() 方法 @SukkaW #4046

    • 這表示您現在可以取消註冊現有的標籤外掛,並使用您自己的同名外掛來取代它。
  • feat(filter): 新增 _after_html_render 過濾器 @jiangtj #4051

    • perf(filter): 將 after_render:html 設定為 _after_html_render 的別名 @curbengh #4073
    • 現有的 after_render:html 過濾器外掛程式會自動從此改進中獲益。
  • feat(load_config): 支援 node_modules 中的 theme_dir @SukkaW #4112

  • fix(list_tags): 為每個元素自訂類別 @noraj #4059

    • list_tags 外掛程式自訂每個元素 <ul><li><a><span> 的類別名稱。

效能

  • perf(tag): 最佳化渲染 @SukkaW #4418
  • 效能(外部連結):更快的正規表達式 & 條件簡寫 @SukkaW #4436
  • 效能(外部連結):最佳化正規表達式 @SukkaW #4008
  • 效能(過濾器):簡寫語法 @SukkaW #4377
  • 效能(反引號程式碼):簡寫 @SukkaW #4369
  • 效能:避免在 'clean' 命令中執行不相關的插件 @curbengh #4386
    • 為了維持與第三方 console 插件的相容性,此變更僅適用於 hexo clean,而非 hexo c 別名。
  • 效能(titlecase):延遲載入 @SukkaW #4417
  • 效能(標籤/程式碼):效能改進 @SukkaW #4416
  • 效能(文章):簡化程式碼區塊跳脫 @SukkaW #4254
  • 效能(meta_generator):避免不必要的檢查 @SukkaW #4208
  • 效能(外部連結):快取設定 @SukkaW #4134
  • 效能(open_graph):避免使用 htmlTag() 並增強快取 @SukkaW #4125
  • 重構(list_archives):減少對 date.format() 的呼叫 @dailyrandomphoto #4011
  • 修復(moment.locale):避免重複使用錯誤的名稱查詢 @dailyrandomphoto #4007

修復

  • 修復(box):忽略主題資料夾中的 .git 和 node modules @jiangtj #4306
  • 修復:允許空的標題 @stevenjoezhang #4344
  • 修復(#4236):當 post_asset_folder 為 true 時,不要建立 “/index” 目錄 @jiangtj #4258
  • 修復(#4317):標籤跳脫的非貪婪正規表達式 @SukkaW #4358
  • 修復(文章):使用非貪婪正規表達式 @stevenjoezhang #4161
  • 修復(文章):正確跳脫文章內的 swig 標籤 @SukkaW #4352
    • 現在,單個反引號內的 swig 標籤會被視為程式碼嵌入。
    • `{% foo %}{{ bar }}{% endfoo %}`
  • 修復(記錄):僅在相關命令中記錄資料庫 @curbengh #4387
    • 將資料庫寫入 ${dbPath}/db.json 訊息不應該在 hexo cleanhexo version 中顯示。
  • 修復(伺服器快取):必須匹配確切的別名 @curbengh #4388
    • 改進與名稱可能以 's' 開頭的第三方 console 插件的相容性。
  • 修復(標籤程式碼):解析 'wrap' 選項 @curbengh #4391
  • 修復:移除未使用的類型檢查 @Himself65 #4398
  • 修復:直接從錯誤物件存取錯誤代碼 @SukkaW #4280
    • 改進與原生 JS API 的相容性
  • 修復:使用額外換行符號 EOF 載入插件 @SukkaW #4256
  • 修復:反引號中解析程式碼錯誤 @seaoak #4229
  • 修復(toc_helper):跳脫類別名稱並處理空 id @curbengh #4009
  • 修復(meta_generator):匹配具有不同順序的現有 <meta> @SukkaW #4017
  • 修復(excerpt):更嚴格的正規表達式 @curbengh #4443
    1. <!--more-->
    2. <!-- more-->
    3. <!--more -->
    4. <!-- more -->

重構

其他

請參閱發行說明以取得完整的變更日誌。