Skip to content

Commit

Permalink
merge #16
Browse files Browse the repository at this point in the history
  • Loading branch information
dixyes committed Nov 29, 2017
2 parents dbe12f1 + 72aaba6 commit 45d2e74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
24 changes: 10 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
*/
'use strict';

// default mark content
const MARK_CONTENT = "dplayer used";

const fs = require('hexo-fs'),
util = require('hexo-util'),
log = require('hexo-log')({name:"hexo-tag-dplayer",debug:false}), // logger
urlFn = require('url'),
path = require('path'),
srcDir = path.dirname(require.resolve('dplayer')),
mark = '<!-- '+ MARK_CONTENT +' -->',
scriptDir = '/assets/js/', // default script directories
styleDir = '/assets/css/',
files = [
Expand Down Expand Up @@ -70,18 +66,18 @@ if (!conf.cdn){
}

hexo.extend.filter.register('after_render:html', (str, data) => {

if(str.includes('</html>') && str.includes(mark)){ //make sure dplayer used in final html
log.debug("got page that dplayer used")
if(str.includes('</html>') && str.includes('class="dplayer hexo-tag-dplayer-mark"')){ //make sure dplayer used in final html
log.debug("got page that dplayer used");
var target = conf.cdn || tbIns,
s = str.replaceAll(mark,'');
s = str;
target.forEach(item => {
//console.log(item);
if (item.endsWith('.css')) {
var tag = util.htmlTag('link', {rel: 'stylesheet', type: 'text/css', href: item });
s = s.substring(0,s.lastIndexOf('</head>'))+tag+s.substring(s.lastIndexOf('</head>'));
s = s.replace(/<\/head>/, tag + '</head>');
}else if (item.endsWith('.js')) {
var tag = util.htmlTag('script', {src: item}, '');
s = s.substring(0,s.indexOf('</body>'))+tag+s.substring(s.indexOf('</body>'));
s = s.replace(/<\/head>/, tag + '</head>');
}else if (item.endsWith('.map')) {
//do nothing when sorce map used
}else{
Expand Down Expand Up @@ -127,7 +123,7 @@ hexo.extend.tag.register('dplayer', (args) => {
const width = opt.width || def.width,
height = opt.height || def.height;
var url = opt.url || def.url;
var raw = '<div id="'+ id + '" class="dplayer" style="margin-bottom: 20px;'+(width ?' width:'+width+';':'')+(height?' height:'+height+';':'')+'"></div>';
var raw = '<div id="'+ id + '" class="dplayer hexo-tag-dplayer-mark" style="margin-bottom: 20px;'+(width ?' width:'+width+';':'')+(height?' height:'+height+';':'')+'"></div>';
if(url != undefined){
if (hexo.config['post_asset_folder'] == true ){
//for #10, if post_asset_folder is enable, regard url as relative url
Expand Down Expand Up @@ -194,11 +190,11 @@ hexo.extend.tag.register('dplayer', (args) => {
return v;
}
}).replace("\"document.getElementById('')\"",'document.getElementById("'+ id +'")') +
');' + (opt.code || def.code || '') + '})()</script>';
//log.debug(opt.code,def.code,(opt.code || def.code || ''))
');window.dplayers||(window.dplayers=[]);window.dplayers.push(player);' + (opt.code || def.code || '') + '})()</script>';
//console.log(opt.code,def.code,(opt.code || def.code || ''));
}
else{
raw += '<p>no url specified, no dplayer _(:3」∠)_</p>';
}
return raw+mark;
return raw;
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"homepage": "https://github.com/MoePlayer/hexo-tag-dplayer#readme",
"dependencies": {
"dplayer": "^1.6.0",
"hexo-fs": "^0.1.6",
"hexo-log": "^0.2.0",
"hexo-util": "^0.6.1"
"hexo-fs": "^0.2.2",
"hexo-util": "^0.6.2"
}
}

0 comments on commit 45d2e74

Please sign in to comment.