2023-10-26 hexo部署到GitHub时css样式不生效 ==》 css文件链接被识别为不安全链接,导致无法生效

发布时间 2023-10-26 23:42:24作者: 哎呦你可棒棒了

hexo d一键部署后查看效果发现博客页面的样式全丢失了,查看控制台发现了端倪:

Mixed Content: The page at 'https://xxx.github.io/' was loaded over HTTPS, but requested an insecure stylesheet 'http://xxx.com/lib/font-awesome/css/font-awesome.min.css?v=4.6.2'. This request has been blocked; the content must be served over HTTPS.

意思就是GitHub账号:https://xxx.github.io是https头的,而css文件存储的路径 http://xxx.com/lib/font-awesome/css/font-awesome.min.css?v=4.6.2

http开头的,被认为是不安全链接,故而无法加载。

解决方案:在博客根目录中找到index.html文件,添加下面代码,用于强制把http转换成https:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />