Valine: Failed to load resource && 匿名头像不显示

博主发现其使用Valine的博客评论系统出现错误,表现为'Failed to load resource'以及匿名用户头像不显示。通过查看控制台,发现问题在于请求的CDN地址。解决方案包括修改评论文件,注释出CDN引用,更新LeanCloud的Server URLs,以及替换Gravatar为可用的SDN。最后,通过GitHub和jsDeliver托管更改后的文件,成功解决了头像显示问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

See this article in my blog: https://dyingdown.github.io/2023/02/07/Valine-Failed-to-load-resource-anonymous-avatar-not-shown/

Recently, I found my blog comment system can’t be used, with an error showing Failed to load resource: net::ERR_NAME_NOT_RESOLVED. And the avatar for the anonymous user is also not shown.

Failed to load resource

After seeing the console, I found that I’m requesting the url https://us.leancloud.cn. Because I used the national version of leancloud, but the valine.min.js uses cn as suffix.

Modify comment file

In order to change that, I need to specify the serverURLs when initiating the Valine object.

window.valine = new Valine({
    el:'#vcomment',
    notify:notify,
    verify:verify,
    appId:'#{theme.valine.appId}',
    appKey:'#{theme.valine.appKey}',
    placeholder:'#{theme.valine.placeholder}',
    avatar:'#{theme.valine.avatar}',
    guest_info:guest_info,
    pageSize:'#{theme.valine.pageSize}',
    lang: '#{theme.valine.lang}',
    serverURLs: '#{theme.valine.serverURLs}',
})

Add serverURLs: '#{theme.valine.serverURLs}', to the end.

Usually, this code is locate in layout/includes/third-party/comment/valine.pug or layout/includes/comment/valine.pug

Comment out cdn

Also, there is an error using https://cdn1.lncld.net/static/js/3.0.4/av-min.js, and its usually in the same file as the new Valine() code.

Modify _config.yml

valine:
  on: true
  appId: ******* # App ID
  appKey: ***** # App Key
  verify: true # 验证码
  notify: true # 评论回复邮箱提醒
  avatar: 'mp' # 匿名者头像选项 https://valine.js.org/avatar.html
  placeholder: Leave your email address so you can get reply from me!
  lang: en
  guest_info: nick,mail,link
  pageSize: 10
  serverURLs: *********

Go to LeanCloud page and find your app.

Then go to settings and then App keys, and find Server URLs: REST API Server URL

Copy this URL to the config file

This url is in the format of https:// + first 8 characters of appId + .api.lncldglobal.com

Anonymous avatar

Now the comment functions works, but the avatar still doesn’t appear properly.

After checking the console, I saw there was a 404 error of Gravatar.

In some cases, the gravatar.loli.net is not able to use, so we can change into sdn.geekzu.org

  1. First opens the Valine.min.js file your theme is using. I’m using https://unpkg.com/valine/dist/Valine.min.js, I used to use https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js
  2. copy open it and copy the code out.
  3. find T={cdn:"https://gravatar.loli.net/avatar/ this in the code
  4. replace them with T={cdn:"https://sdn.geekzu.org/avatar/"

In order not to lose the speed of loading page, we put the change into a cdn. I’m using GitHub and jsDeliver.

  1. First commit the file into a GitHub repository
  2. copy the link of your file, to this jsDeliver page
  3. copy the new link to replace the old cdn url.

And refresh the site, now the avatar works normally.

References

Valine 无法评论的解决方案

valine评论系统不能使用

解决Valine无法加载头像的方法

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值