-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathinit-hugo-lunr.js
42 lines (35 loc) · 1.06 KB
/
init-hugo-lunr.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
#!/usr/bin/env node
/**
* Initialize Hugo-Lunr indexing
*/
var hugolunr = require('hugo-lunr');
var path = require('path');
var indexer = new hugolunr();
var entities = require('entities');
// Process file content before adding to index JSON file
var readFileCallback = function (fileData) {
if (!fileData.content) {
return fileData;
}
// Strip Hugo shortcodes
fileData.content = fileData.content.replace(/{{ \w+ .*?}}/gi, '');
// Decode HTML entities
fileData.content = entities.decodeHTML(fileData.content);
return fileData;
};
const contentDir = 'content';
indexer.setInput(path.join(contentDir, '**'));
indexer.setOutput('themes/hackshackers-2017/static/lib/lunr-index.json');
indexer.setExcludes([
path.join(contentDir, 'data', '**'),
path.join(contentDir, 'content-images', '**'),
path.join(contentDir, '**/README.md'),
path.join(contentDir, '_index.md'),
]);
indexer.setFileOpts({
matter: { delims: '---', lang: 'yaml' },
taxonomies: ['tags', 'categories', 'authors'],
params: ['date'],
callback: readFileCallback
});
indexer.index();