-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (42 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* 替换 html 内的非标准的资源属性
* @author ydr.me
* @create 2016-01-12 21:27
*/
'use strict';
var object = require('blear.utils.object');
var pkg = require('./package.json');
var defaults = {
attributeName: 'data-original',
tagName: 'img',
progress: 'pre-html'
};
var COOLIE_IGNORE = 'coolieignore';
module.exports = function (configs) {
configs = object.assign({}, defaults, configs);
return function (options) {
if (options.progress !== configs.progress) {
return options;
}
var coolie = this;
options.code = coolie.matchHTML(options.code, {
tag: configs.tagName
}, function (node) {
if (!node.attrs[configs.attributeName]) {
return node;
}
// coolieignore
if (node.attrs[COOLIE_IGNORE]) {
node.attrs[COOLIE_IGNORE] = null;
return node;
}
var url = node.attrs[configs.attributeName];
var ret = coolie.buildResPath(url, options.file);
node.attrs[configs.attributeName] = ret.url;
return node;
});
return options;
};
};
module.exports.package = pkg;
module.exports.defaults = defaults;