hexo-asset-image
Advanced tools
Comparing version 0.0.3 to 0.0.4
59
index.js
@@ -13,6 +13,16 @@ 'use strict'; | ||
var link = data.permalink; | ||
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 beginPos = getPosition(link, '/', 3) + 1; | ||
var appendLink = ''; | ||
// In hexo 3.1.1, the permalink of "about" page is like ".../about/index.html". | ||
// if not with index.html endpos = link.lastIndexOf('.') + 1 support hexo-abbrlink | ||
if(/.*\/index\.html$/.test(link)) { | ||
// when permalink is end with index.html, for example 2019/02/20/xxtitle/index.html | ||
// image in xxtitle/ will go to xxtitle/index/ | ||
appendLink = 'index/'; | ||
var endPos = link.lastIndexOf('/'); | ||
} | ||
else { | ||
var endPos = link.lastIndexOf('.'); | ||
} | ||
link = link.substring(beginPos, endPos) + '/' + appendLink; | ||
@@ -22,3 +32,3 @@ var toprocess = ['excerpt', 'more', 'content']; | ||
var key = toprocess[i]; | ||
var $ = cheerio.load(data[key], { | ||
@@ -32,17 +42,26 @@ ignoreWhitespace: false, | ||
$('img').each(function(){ | ||
// For windows style path, we replace '\' to '/'. | ||
var src = $(this).attr('src').replace('\\', '/'); | ||
if(!/http[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 != ''; | ||
}); | ||
if(linkArray[linkArray.length - 1] == srcArray[0]) | ||
srcArray.shift(); | ||
src = srcArray.join('/'); | ||
$(this).attr('src', '/' + link + src); | ||
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) | ||
|| /^\s*\/uploads|images\//.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)); | ||
} | ||
@@ -49,0 +68,0 @@ }); |
{ | ||
"name": "hexo-asset-image", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Give asset image in hexo a absolutely path automatically", | ||
@@ -15,7 +15,8 @@ "main": "index.js", | ||
], | ||
"author": "codefalling", | ||
"author": "xcodebuild", | ||
"license": "MIT", | ||
"dependencies": { | ||
"cheerio": "^0.19.0" | ||
"cheerio": "^0.19.0", | ||
"entities": "^1.1.2" | ||
} | ||
} |
@@ -25,1 +25,5 @@ # hexo-asset-image | ||
Just use `![logo](logo.jpg)` to insert `logo.jpg`. | ||
# History | ||
2018-04-18: support hexo-abbrlink |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4387
63
29
2
4
1
+ Addedentities@^1.1.2