Skip to content
This repository has been archived by the owner on Feb 18, 2020. It is now read-only.

TypeError: Cannot read property 'replace' of undefined #15

Open
LiuZhe6 opened this issue Feb 8, 2017 · 3 comments
Open

TypeError: Cannot read property 'replace' of undefined #15

LiuZhe6 opened this issue Feb 8, 2017 · 3 comments

Comments

@LiuZhe6
Copy link

LiuZhe6 commented Feb 8, 2017

下载完成后,进行hexo g时出现错误。
错误代码如下:不知是何原因
$ hexo g
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/do cs/troubleshooting.html
TypeError: Cannot read property 'replace' of undefined
at Object. (D:\Hexo\blog\node_modules\hexo-asset-image\index.js:3 1:38)
at exports.each (D:\Hexo\blog\node_modules\cheerio\lib\api\traversing.js:293 :24)
at Hexo. (D:\Hexo\blog\node_modules\hexo-asset-image\index.js:29: 16)
at Hexo.tryCatcher (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\js\ main\util.js:26:23)
at Hexo. (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\js \main\method.js:15:34)
at D:\Hexo\blog\node_modules\hexo\lib\extend\filter.js:68:35
at tryCatcher (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\js\main\ util.js:26:23)
at ReductionPromiseArray._promiseFulfilled (D:\Hexo\blog\node_modules\hexo\n ode_modules\bluebird\js\main\reduce.js:105:38)
at Promise._settlePromiseAt (D:\Hexo\blog\node_modules\hexo\node_modules\blu ebird\js\main\promise.js:589:26)
at Promise._settlePromises (D:\Hexo\blog\node_modules\hexo\node_modules\blue bird\js\main\promise.js:700:14)
at Async._drainQueue (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\j s\main\async.js:123:16)
at Async._drainQueues (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\ js\main\async.js:133:10)
at Immediate.Async.drainQueues (D:\Hexo\blog\node_modules\hexo\node_modules\ bluebird\js\main\async.js:15:14)
at runCallback (timers.js:570:20)
at tryOnImmediate (timers.js:550:5)
at processImmediate [as _immediateCallback] (timers.js:529:5)
FATAL Cannot read property 'replace' of undefined
TypeError: Cannot read property 'replace' of undefined
at Object. (D:\Hexo\blog\node_modules\hexo-asset-image\index.js:3 1:38)
at exports.each (D:\Hexo\blog\node_modules\cheerio\lib\api\traversing.js:293 :24)
at Hexo. (D:\Hexo\blog\node_modules\hexo-asset-image\index.js:29: 16)
at Hexo.tryCatcher (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\js\ main\util.js:26:23)
at Hexo. (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\js \main\method.js:15:34)
at D:\Hexo\blog\node_modules\hexo\lib\extend\filter.js:68:35
at tryCatcher (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\js\main\ util.js:26:23)
at ReductionPromiseArray._promiseFulfilled (D:\Hexo\blog\node_modules\hexo\n ode_modules\bluebird\js\main\reduce.js:105:38)
at Promise._settlePromiseAt (D:\Hexo\blog\node_modules\hexo\node_modules\blu ebird\js\main\promise.js:589:26)
at Promise._settlePromises (D:\Hexo\blog\node_modules\hexo\node_modules\blue bird\js\main\promise.js:700:14)
at Async._drainQueue (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\j s\main\async.js:123:16)
at Async._drainQueues (D:\Hexo\blog\node_modules\hexo\node_modules\bluebird\ js\main\async.js:133:10)
at Immediate.Async.drainQueues (D:\Hexo\blog\node_modules\hexo\node_modules\ bluebird\js\main\async.js:15:14)
at runCallback (timers.js:570:20)
at tryOnImmediate (timers.js:550:5)
at processImmediate [as _immediateCallback] (timers.js:529:5)

@zhanjinhao
Copy link

你解决这个问题没,我也遇到了这个问题

@zhanjinhao
Copy link

解决这个问了,把node_modules/hexo-asset-image/index.js文件里的内容替换为:

'use strict';
var cheerio = require('cheerio');

// http://stackoverflow.com/questions/14480345/how-to-get-the-nth-occurrence-in-a-string
function getPosition(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();
}

}
});

@xcodebuild
Copy link
Owner

0.0.4 版本中是否仍然存在?

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

No branches or pull requests

3 participants