Butterfly主题引入Dplayer播放器,并适配pjax
AI-摘要
切换
YA GPT
AI初始化中...
介绍自己 🙈
生成本文简介 👋
推荐相关文章 📖
前往主页 🏠
前往爱发电购买
Butterfly主题引入Dplayer播放器,并适配pjax
檐牙点击查看更新记录
更新记录
2024-6-6: 适配方案01
依样画葫芦尝试pjax适配
效果预览
魔改正文
本方案目前只是根据原有的Aplayer播放器适配进行依样画葫芦
如果有更好的方法,欢迎各位看官提出
点击查看魔改正文
在博客根目录打开
CMD
,输入npm
安装指令,安装Dplayer插件1
npm install hexo-tag-dplayer --save
新建
[根目录]\themes\butterfly\layout\includes\third-party\dplayer.pug
1
script(src=url_for(theme.asset.dplayer_js))
修改
[根目录]\themes\butterfly\layout\includes\additional-js.pug
在大约53行的位置1
2
3
4
5
6
7if theme.aplayerInject && theme.aplayerInject.enable
if theme.pjax.enable || theme.aplayerInject.per_page
include ./third-party/aplayer.pug
+ include ./third-party/dplayer.pug
else if page.aplayer
include ./third-party/aplayer.pug
+ include ./third-party/dplayer.pug修改
[根目录]\themes\butterfly\layout\includes\third-party\pjax.pug
在大约41行下面的位置,依样画葫芦,添加适配代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15if (window.aplayers) {
for (let i = 0; i < window.aplayers.length; i++) {
if (!window.aplayers[i].options.fixed) {
window.aplayers[i].destroy()
}
}
}
+ if (window.dplayers) {
+ for (let i = 0; i < window.dplayers.length; i++) {
+ if (!window.dplayers[i].options.fixed) {
+ window.dplayers[i].destroy()
+ }
+ }
+ }最后打开
[根目录]\_config.butterfly.yml
添加CDN配置项1
2
3
4
5
6option:
main_css: /css/index.css
main: /js/main.js
utils: /js/utils.js
+ #dplayer播放器
+ dplayer_js: https://npm.elemecdn.com/dplayer@1.26.0/dist/DPlayer.min.js
使用方式
详情见官方文档
官方举例:
1
2{% dplayer "url=https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.mp4" "addition=https://dplayer.daoapp.io/bilibili?aid=4157142" "api=https://api.prprpr.me/dplayer/" "pic=https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.jpg" "id=9E2E3368B56CDBB4" "loop=yes" "theme=#FADFA3" "autoplay=false" "token=tokendemo" %}
{% dplayer 'url=some.mp4' "id=someid" "api=https://api.prprpr.me/dplayer/" "addition=/some.json" 'code=player.on("loadstart",function(){console.log("loadstart")})' "autoplay" %}本人使用的:
评论
隐私政策
✅ 你无需删除空行,直接评论以获取最佳展示效果