hexo博客相关模板dplayer报错

问题描述

最近搭建了 Hexo 感觉很不错,但是引入 DPlayer 视频资源老是报错如下内容:

1
2
3
4
5
6
7
8
9
10
11
Uncaught ReferenceError: DPlayer is not defined
at <anonymous>:1:26
at <anonymous>:1:327
at module.exports (pjax.min.js:1:7651)
at pjax.min.js:1:9113
at NodeList.forEach (<anonymous>)
at module.exports (pjax.min.js:1:9364)
at module.exports (pjax.min.js:1:8931)
at pjax.min.js:1:4649
at NodeList.forEach (<anonymous>)
at module.exports (pjax.min.js:1:9364)

这样会导致页面第一次进入时,DPlayer 不会被加载,导致视频无法播放,需要重新刷新才能加载视频,非常闹心。

官方回应

在网上找了一圈,官方给的回答是这样的:

官方回答
只能说很模糊,没有说 exclude 到底该写哪个目录,在网上找了一个解决方案。
解决方案
说实话,还是很模糊。自己尝试了很多目录,踩了很多坑,终于解决了。

解决方法

具体解决方法如下:

  1. 找到相应模板配置文件 _config.anzhiyu.yml
  2. 找到如下代码行:
    1
    2
    3
    4
    pjax:
    enable: true
    exclude:
    - /article/%E5%BC%BA%E9%A3%8E%E5%90%B9%E6%8B%82/ # 排除目录,实际上就是网址对应的目录,比如我的:https://blog.foan.cc/article/强风吹拂/ 填写 /article/强风吹拂/ 即可,对了,不支持中文。
  3. 最后重新编译启动 Hexo 即可:
    1
    hexo cl;hexo s

总结

希望这篇文章能帮到大家解决 Hexo 引入 DPlayer 视频资源时的报错问题,如果你有其他更好的解决方案或建议,欢迎在评论区讨论交流。