-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (34 loc) · 847 Bytes
/
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
'use strict';
var through = require('through');
var gutil = require('gulp-util');
var lunr = require('lunr');
var File = gutil.File;
var PluginError = gutil.PluginError;
module.exports = function(targetFile) {
if (!targetFile) {
throw new PluginError('gulp-lunr', 'Missing outputFile option for gulp-lunr');
}
var index;
function add(file) {
if (!index) {
index = lunr(function() {
this.field('body');
this.ref('href');
});
}
index.add({
body: file.contents.toString(),
href: file.path
});
return;
}
function end() {
var content = new Buffer(JSON.stringify(index.toJSON()));
var target = new File();
target.path = targetFile;
target.contents = content;
this.emit('data', target);
this.emit('end');
}
return through(add, end);
};