CSS样式无法加载

git push 博客文件后,会发现样式无法正常加载

F12打开network,检查css文件正常获取,控制台报错

blog.badend.cn/:2 Failed to find a valid digest in the 'integrity' attribute for resource 'https://blog.badend.cn/assets/css/stylesheet.d72444526d7ecbdb0015438a7fa89054a658bf759d0542e2e5df81ce94b493ee.css' with computed SHA-256 integrity '1vzSCk+4bvpN+sjsldpgJEzIhxBCGD2h7yjjp2Ktecg='. The resource has been blocked.

原因分析

windows下用hugo生成的静态文件结尾是LF,而git在提交文件时会将LF替换为CRLF,破坏了文件的完整性,因为之前的博客都是在linux环境下写的,所以没遇到这个问题….

git提交时警告

warning: in the working copy of 'page/1/index.html', LF will be replaced by CRLF the next time Git touches it

解决方法

禁用git的自动替换功能

git config core.autocrlf false

或者全局禁用

git config --global core.autocrlf false

禁用后重新提交文件,css样式正常显示

其他

需要注意的是,对于在 Github Pages 上部署的用户,请在根目录创建一个.nojekyll文件以允许访问以_ 开头的文件夹(例如_framework_static

这是因为github pages的jekyll模版会忽略下划线开头的文件,所以要禁用jekyll