根本原因:git crlf 设置导致推送到 github 的文件变动。

Hugo 静态博客,使用 PaperMode 主题,本地渲染没问题,将 publish 文件夹 push<username>.github.io 后,通过 Github Page 访问会出现 CSS block 的情况:

hugo local v.s. online

尝试过但不起作用的方法

  1. 修改 config.toml 中的 baseURL,用 http、用 https
  2. 根据 head, footer: add option to disable fingerprinting adityatelange#89, 在 config.toml 中加入如下内容:
1
2
[params.assets]
  disableFingerprinting = true

我的解决方法

根据 Failed to find a valid digest in the integrity attribute,问题可能是 git line breaking 的问题,我使用的是 macOS,当时的 git config -l 中:

1
core.autocrlf=true

hugo project repo 和 我的 github.io repo 中 执行

1
git config core.autocrlf false

然后生成博客:

1
2
3
4
5
6
7
8
cd blog-hugo
hugo -t PaperMod

# publish is <username>.github.io repo as a submodule
cd publish
git add .
git commit -m "fix online theme"
git push

完美解决:

fixed online

其它未尝试的方法

  • 修改模版中的 integrity="{{ xxxx }}"integrity=""
  • git config --global core.autocrlf input
  • CloudFlare Cache