Hugo主题部署至GitHub后加载失败,如何修复完整性校验问题?
The integrity error you're encountering stems from a line ending mismatch: Hugo generates the SHA-256 hash locally using Windows' CRLF line endings, but GitHub Pages serves files with LF line endings (Git often converts CRLF to LF during deployment). This causes the computed hash to fail validation. Here's how to fix this properly without disabling integrity checks:
1. Enforce Consistent Line Endings Across Repositories
Add a .gitattributes file to both your content repository (blog) and your GitHub Pages hosting repository (matthewcrews.github.io). This tells Git to standardize all text files to LF line endings, regardless of your local OS:
* text=auto eol=lf
With this file in place, Git will convert CRLF to LF when you commit files from Windows, ensuring the deployed files use the same line endings Hugo used to generate the integrity hash.
2. Clean and Rebuild Your Site
After setting up .gitattributes, regenerate your static files with the correct line endings:
- Run
hugo cleanto delete old build artifacts - Rebuild your site with
hugo - Commit the new static files to your content repository, then push to trigger GitHub Pages deployment (or manually sync to your hosting repo)
This will generate new integrity hashes aligned with LF line endings, matching what will be served on GitHub Pages.
3. Optional: Explicitly Configure Hugo Resource Handling
If the above steps don't resolve the issue, add explicit resource processing settings to your config.toml to ensure consistent hash generation:
[module] [[module.mounts]] source = "assets" target = "assets" [[module.mounts]] source = "static" target = "static" [resources] [resources.css] minify = true integrity = true
This config clarifies how Hugo should handle asset files, ensuring minification and integrity hash generation use consistent formatting.
Once you complete these steps, the browser will validate the integrity hash correctly, and your theme's CSS will load without being blocked.
内容的提问来源于stack exchange,提问作者Matthew Crews

