diff --git a/index.js b/index.js index b314020..919d45c 100644 --- a/index.js +++ b/index.js @@ -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 = '', scriptDir = '/assets/js/', // default script directories styleDir = '/assets/css/', files = [ @@ -70,18 +66,18 @@ if (!conf.cdn){ } hexo.extend.filter.register('after_render:html', (str, data) => { - - if(str.includes('') && str.includes(mark)){ //make sure dplayer used in final html - log.debug("got page that dplayer used") + if(str.includes('') && 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(''))+tag+s.substring(s.lastIndexOf('')); + s = s.replace(/<\/head>/, tag + ''); }else if (item.endsWith('.js')) { var tag = util.htmlTag('script', {src: item}, ''); - s = s.substring(0,s.indexOf(''))+tag+s.substring(s.indexOf('')); + s = s.replace(/<\/head>/, tag + ''); }else if (item.endsWith('.map')) { //do nothing when sorce map used }else{ @@ -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 = '
'; + var raw = '
'; if(url != undefined){ if (hexo.config['post_asset_folder'] == true ){ //for #10, if post_asset_folder is enable, regard url as relative url @@ -194,11 +190,11 @@ hexo.extend.tag.register('dplayer', (args) => { return v; } }).replace("\"document.getElementById('')\"",'document.getElementById("'+ id +'")') + - ');' + (opt.code || def.code || '') + '})()'; - //log.debug(opt.code,def.code,(opt.code || def.code || '')) + ');window.dplayers||(window.dplayers=[]);window.dplayers.push(player);' + (opt.code || def.code || '') + '})()'; + //console.log(opt.code,def.code,(opt.code || def.code || '')); } else{ raw += '

no url specified, no dplayer _(:3」∠)_

'; } - return raw+mark; + return raw; }); diff --git a/package.json b/package.json index 283328e..51a4361 100644 --- a/package.json +++ b/package.json @@ -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" } }