Hexo NexT百度分享不支持https问题

在 NexT 主题中已经预置了百度分享功能,通过主题配置文件中的 baidushare 即可开启,根据 next/layout/_partials/share/baidushare.swig 中已经预设的 type 类型。

1
2
3
4
5
6
{% if theme.baidushare.type === "button" %}
...
...
{% elseif theme.baidushare.type === "slide" %}
...
...

可以配置:

1
2
baidushare:
type: button # or slide

这样配置以后,文章的末尾已经出现了分享按钮了,如图:

nO84AS.png

不过文章部署 github 后,分享按钮没有显示,查看浏览器控制台,报错了:

nOGkB6.png

大概意思是跨源了,因为百度分享不支持 Https,站点配置文件中也有提示:Warning: Baidu Share does not support https.

网上找到了解决方案,参考:

github baiduShare

百度分享不支持 https 的解决方案

操作步骤如下:

1、下载github baiduShare代码

解压后将 static 文件夹拷贝到自己项目 next/source/ 目录下

2、修改 next/layout/_partials/share/baidushare.swig 文件

将文件最后的代码

1
with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];

替换为

1
with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];

即修改 src 后边的引用,改为本项目目录下的 js 文件

最后重新生成博文,打开文章后,即可看到分享按钮了,经测试,分享功能已经可以正常使用了

如有其它问题,可参考:

百度分享不支持 https 的解决方案

点击查看

本文标题:Hexo NexT百度分享不支持https问题

文章作者:北宸

发布时间:2019年08月17日 - 21:06:21

最后更新:2023年08月19日 - 13:26:00

原始链接:https://www.liaofuzhan.com/posts/952735405.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------------本文结束 感谢您的阅读-------------------
🌞