使用 Hexo-Tag-Aplayer 插件

首先执行安装命令:

1
npm install --save hexo-tag-aplayer

如果出现报错:

1、清除npm缓存

1
npm cache clean --force

2、禁用SSL:虽然不推荐,但您可以暂时禁用SSL验证来解决这个问题。但请注意,这会降低安全性。您可以通过设置npm的 strict-ssl 选项为 false 来实现:

1
npm config set strict-ssl false

参考这篇文章:Hexo博客技巧:为博客插入音乐_hexo添加音乐-CSDN博客

关闭 asset_inject

主题配置文件

此步骤适用于安装了hexo-tag-aplayer插件的人

由于需要全局都插入aplayer和meting资源,为了防止插入重复的资源,需要把asset_inject设为false

1
2
3
aplayer:
meting: true
asset_inject: false

开启主题的AplayerInject

在主题的配置文件中,enable设为trueper_page设为true

1
2
3
4
# Inject the css and script (aplayer/meting)
aplayerInject:
enable: true
per_page: true

把Aplayer代码插入到主题配置文件

其中data-server为音乐平台,例如netease就是网易云,还有tencent, kugou, xiami, baidu等;

id即为你选择的音乐平台网页版点击我的喜欢页面,地址栏上方的id

1
2
3
4
5
inject:
head:
bottom:
- <div class="aplayer no-destroy" data-id="7868042847" data-server="tencent" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="true" muted></div>

跳转页面,音乐会重新加载?

1、记得添加class="aplayer no-destroy"

2、将主题配置文件中的pjax设置为true

1
2
3
4
5
pjax: 
enable: true
exclude:
- /music/
- /no-pjax/

ok,执行以上操作你应该可以在左下角看到一个音乐播放器