Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

插件js在首页中重复加载的解决方案(暂时) #1

Closed
Myer921 opened this issue Sep 6, 2016 · 7 comments
Closed

插件js在首页中重复加载的解决方案(暂时) #1

Myer921 opened this issue Sep 6, 2016 · 7 comments

Comments

@Myer921
Copy link
Collaborator

Myer921 commented Sep 6, 2016

在一部分主题中,主题会将所有文章内容放到首页中,但这样会导致了aplayer以及dplayer插件js的重复加载
(打开控制台 看看是不是多了好几行的dplayer的标识)
这对于用户访问来说是不好的
暂行解决方案
修改/hexo网站目录/node_modules/hexo-tag-(括号删除,这里填你要编辑的插件,aplayer写a,dplayer写d)player/index.js

将此段代码注释,并魔改主题

hexo.extend.filter.register('after_post_render', function(data) {
    data.content =
        util.htmlTag('script', {src: '/' + scriptDir + aplayerScript}, " ") +
        data.content;
    return data;
});

修改主题目录的head.js文件

/hexo网站目录/themes/主题名称/layout/_partial/head.js

</head>前一行添加
请根据需要添加对应行

  <script src="/assets/js/DPlayer.min.js"></script>
  <script src="/assets/js/APlayer.min.js"></script>

并执行一次

 hexo clean && hexo g

让其生效

@Myer921
Copy link
Collaborator Author

Myer921 commented Sep 6, 2016

如果有更好方案,欢迎探讨

@dixyes
Copy link
Member

dixyes commented Sep 6, 2016

倒不如说是hexo设计的问题,但是我这么懒的人 会使用

<!-- more -->

这样的标签避免主页出现a/dplayer
(虽然自己并不用

@Myer921
Copy link
Collaborator Author

Myer921 commented Sep 6, 2016

<!-- more -->

这个要怎么用?????

@Myer921 Myer921 changed the title 与某些主题配合不佳的暂行解决方案 与某些主题配合不佳的暂时解决方案 Sep 6, 2016
@Myer921 Myer921 changed the title 与某些主题配合不佳的暂时解决方案 插件js在首页中重复加载的解决方案(暂时) Sep 6, 2016
@dixyes
Copy link
Member

dixyes commented Sep 6, 2016

嗯。。。我找遍了hexo源码,但没有找到可以在渲染theme时用的filter。。。建议要是大量使用dplayer就改模板吧,小量使用可以这样使用:

---
title: 标题
date: 2333-33-33 33:33:33
tags:
---

#标题
正文(提纲)
<!-- more -->
{% raw %}
<div id="player1" class="dplayer"></div>
<script src="dist/DPlayer.min.js"></script><!-- 注意,这行在more注释之后 -->
<script>
var option = {
    element: document.getElementById('player1'),                       // Optional, player element
    autoplay: false,                                                   // Optional, autoplay video, not supported by mobile browsers
    theme: '#FADFA3',                                                  // Optional, theme color, default: #b7daff
    loop: true,                                                        // Optional, loop play music, default: true
    lang: 'zh',                                                        // Optional, language, `zh` for Chinese, `en` for English, default: Navigator language
    screenshot: true,                                                  // Optional, enable screenshot function, default: false, NOTICE: if set it to true, video and video poster must enable Cross-Origin
    hotkey: true,                                                      // Optional, binding hot key, including left right and Space, default: true
    preload: 'auto',                                                   // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'auto'
    video: {                                                           // Required, video info
        url: '若能绽放光芒.mp4',                                         // Required, video url
        pic: '若能绽放光芒.png'                                          // Optional, music picture
    },
    danmaku: {                                                         // Optional, showing danmaku, ignore this option to hide danmaku
        id: '9E2E3368B56CDBB4',                                        // Required, danmaku id, NOTICE: it must be unique, can not use these in your new player: `https://dplayer.daoapp.io/list`
        api: 'https://dplayer.daoapp.io/',                             // Required, danmaku api
        token: 'tokendemo',                                            // Optional, danmaku token for api
        maximum: 1000                                                  // Optional, maximum quantity of danmaku
    }
}
var dp = new DPlayer(option);
</script>
{% endraw %}

@Myer921
Copy link
Collaborator Author

Myer921 commented Sep 7, 2016

我才看到这文章日期,豆子你这么作死真的好吗?

@dixyes
Copy link
Member

dixyes commented Sep 7, 2016

你不说我都没注意到 目测我电脑时间错乱了

@Myer921
Copy link
Collaborator Author

Myer921 commented Sep 8, 2016

玩的真好 未来的豆子你好

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants