问题
评论中的头像加载不出来,而且在博客设置中更换源也不起作用
排查问题
问题时的头像src
![](http://eternityz.gitee.io/image/image_hosting/blog/halo/halo1.48%E4%BD%BF%E7%94%A8%E5%AF%92%E5%B1%B1%E4%B8%BB%E9%A2%98%E8%AE%BE%E7%BD%AEGravatar%E9%95%9C%E5%83%8F%E6%BA%90%E6%97%A0%E6%95%88%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/%E8%AE%BF%E9%97%AE%E4%B8%8D%E9%80%9A%E7%9A%84%E9%95%9C%E5%83%8F%E6%BA%90.png)
通过手动替换镜像源,发现可以出现头像
![](http://eternityz.gitee.io/image/image_hosting/blog/halo/halo1.48%E4%BD%BF%E7%94%A8%E5%AF%92%E5%B1%B1%E4%B8%BB%E9%A2%98%E8%AE%BE%E7%BD%AEGravatar%E9%95%9C%E5%83%8F%E6%BA%90%E6%97%A0%E6%95%88%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/%E6%9B%B4%E6%8D%A2%E4%B9%8B%E5%90%8E%E5%8F%AF%E4%BB%A5%E8%AE%BF%E9%97%AE%E9%80%9A.png)
通过排查,定位到是//cdn.jsdelivr.net/npm/halo-comment@latest/dist/halo-comment.min.js的问题,中间的参数使用了//cdn.v2ex.com/gravatar这个镜像源,这个镜像源已经访问不通了,需要把这个js中的镜像源替换掉。
![](/Users/eternity/project/image/image_hosting/blog/halo/halo1.48%E4%BD%BF%E7%94%A8%E5%AF%92%E5%B1%B1%E4%B8%BB%E9%A2%98%E8%AE%BE%E7%BD%AEGravatar%E9%95%9C%E5%83%8F%E6%BA%90%E6%97%A0%E6%95%88%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95/%E9%97%AE%E9%A2%98%E4%BD%8D%E7%BD%AE.png)
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
然后评论模块的头像就可以显示了