user@user-W65KJ1-KK1:~/blog$ cnpm install --save hexo-deployer-git ⠹ [0/1] Installing domelementtype@^2.0.1platform unsupported hexo-deployer-git@2.1.0 › hexo-fs@2.0.1 › chokidar@3.5.1 › fsevents@~2.3.1 Package require os(darwin) not compatible with your platform(linux) [fsevents@~2.3.1] optional install error: Package require os(darwin) not compatible with your platform(linux) ✔ Installed 1 packages ✔ Linked 77 latest versions [1/1] scripts.postinstall hexo-deployer-git@2.1.0 › hexo-util@1.9.1 › highlight.js@^9.13.1 run "node deprecated.js", root: "/home/user/blog/node_modules/_highlight.js@9.18.5@highlight.js" -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Verion 9 of Highlight.js has reached EOL. It will no longer be supported or receive security updates in the future. Please upgrade to version 10 or encourage your indirect dependencies to do so.
For more info: https://github.com/highlightjs/highlight.js/issues/2877 https://github.com/highlightjs/highlight.js/blob/master/VERSION_10_UPGRADE.md -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* [1/1] scripts.postinstall hexo-deployer-git@2.1.0 › hexo-util@1.9.1 › highlight.js@^9.13.1 finished in 377ms ✔ Run 1 scripts deprecate hexo-deployer-git@2.1.0 › hexo-util@1.9.1 › highlight.js@^9.13.1 Support has ended for 9.x series. Upgrade to @latest Recently updated (since 2021-03-28): 3 packages (detail see file /home/user/blog/node_modules/.recently_updates.txt) ✔ All packages installed (80 packages installed from npm registry, used 2s(network 2s), speed 924.7kB/s, json 78(211.08kB), tarball 1.66MB)
// http://stackoverflow.com/questions/14480345/how-to-get-the-nth-occurrence-in-a-string functiongetPosition(str, m, i) { return str.split(m, i).join(m).length; }
var version = String(hexo.version).split('.'); hexo.extend.filter.register('after_post_render', function(data){ var config = hexo.config; if(config.post_asset_folder){ var link = data.permalink; if(version.length > 0 && Number(version[0]) == 3) var beginPos = getPosition(link, '/', 1) + 1; else var beginPos = getPosition(link, '/', 3) + 1; // In hexo 3.1.1, the permalink of "about" page is like ".../about/index.html". var endPos = link.lastIndexOf('/') + 1; link = link.substring(beginPos, endPos);
var toprocess = ['excerpt', 'more', 'content']; for(var i = 0; i < toprocess.length; i++){ var key = toprocess[i]; var $ = cheerio.load(data[key], { ignoreWhitespace: false, xmlMode: false, lowerCaseTags: false, decodeEntities: false });
$('img').each(function(){ if ($(this).attr('src')){ // For windows style path, we replace '\' to '/'. var src = $(this).attr('src').replace('\\', '/'); if(!/http[s]*.*|\/\/.*/.test(src) && !/^\s*\//.test(src)) { // For "about" page, the first part of "src" can't be removed. // In addition, to support multi-level local directory. var linkArray = link.split('/').filter(function(elem){ return elem != ''; }); var srcArray = src.split('/').filter(function(elem){ return elem != '' && elem != '.'; }); if(srcArray.length > 1) srcArray.shift(); src = srcArray.join('/'); $(this).attr('src', config.root + link + src); console.info&&console.info("update link as:-->"+config.root + link + src); } }else{ console.info&&console.info("no src attr, skipped..."); console.info&&console.info($(this)); } }); data[key] = $.html(); } } });