问题
评论中的头像加载不出来,而且在博客设置中更换源也不起作用
排查问题
问题时的头像src
通过手动替换镜像源,发现可以出现头像
通过排查,定位到是//cdn.jsdelivr.net/npm/halo-comment@latest/dist/halo-comment.min.js的问题,中间的参数使用了//cdn.v2ex.com/gravatar这个镜像源,这个镜像源已经访问不通了,需要把这个js中的镜像源替换掉。
1.打开文件https://cdn.jsdelivr.net/npm/halo-comment@latest/dist/halo-comment.min.js
2.将js复制到一个新文件halo-comment.min.js中,同时将上述图片中的//cdn.v2ex.com/gravatar镜像源替换掉,可以使用//sdn.geekzu.org/avatar或者//gravatar.loli.net/avatar都可以
3.将新的js放置到一个可以访问的位置,例如七牛云或者nginx相关的目录下,我是放置在了nginx目录下
server {
listen 80;
listen [::]:80;
#server_name www.youdomain.com;
client_max_body_size 1024m;
location / {
proxy_pass http://halo;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# halo-comment.min.js放置在了/www目录下
location /halo-comment {
root /www;
}
}
通过链接访问一下,是否能请求通。http://域名或者ip/halo-comment/halo-comment.min.js,能访问通就OK了。
4.在halo的后台中找到外观--主题编辑,找到寒山主题
在module--script.ftl中替换js文件
原文件
...
<#if settings.auto_night_mode>
<script src="//cdn.jsdelivr.net/gh/hshanx/halo-comment-normal@v1.0.0/dist/halo-comment.min.js"></script>
<#else>
<script src="${options.comment_internal_plugin_js!'//cdn.jsdelivr.net/gh/hshanx/halo-comment-normal@v1.0.0/dist/halo-comment.min.js'}"></script>
</#if>
...
修改之后
...
<#if settings.auto_night_mode>
<script src="//域名或者ip/halo-comment/halo-comment.min.js"></script>
<#else>
<script src="${options.comment_internal_plugin_js!'//域名或者ip/halo-comment/halo-comment.min.js'}"></script>
</#if>
...
5.在halo管理后台中找到『系统--博客设置--评论设置』
将评论模块 JS:中的内容进行替换,替换为自己的js的位置,//域名或者ip/halo-comment/halo-comment.min.js
然后评论模块的头像就可以显示了