【Docusaurus】解決 showLastUpdateTime 顯示相同日期
如題,在 Docusaurus
可以設定 showLastUpdateTime
以及 showLastUpdatAuthor
,就可以在文章結尾顯示最新的更新時間及作者

不過如果你發現發佈後的日期每一篇都是一樣的,這一篇就是來幫助你解決問題!
本地端測試
首先先在本地端進行打包測試
npm run build
打包完後執行
npm run serve
如果在本地端的更新日期不是正確的,那可能是你的 Docusaurus
是舊版的,這個功能是 V2 才有的,更新到最新的版本就可以了。
如果在本地端的更新日期是正確的,且跟我一樣是用 GitHub Actions 進行部署的話,那你就是遇到跟我一樣的問題!
GitHub Actions
只要在 deploy.yml
中的 actions/checkout@v3
加入 fetch-depth: 0
,就可以解決囉!
jobs:
deploy:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
詳細的可以參考 actions/checkout
主要是因為預設是 1
,就是 GitHub Acitons 只 fetch 一個 commit 而已,所以才會都只顯示同一個日期,設定為 0
的話就會抓所有的 commit 時間了!