UNPKG

747 BJavaScriptView Raw
1'use strict';
2
3var defaults = require('./defaults');
4
5module.exports = function(file, options) {
6 var opts = defaults(options);
7
8 if (file.data == null) {
9 file.data = {};
10 }
11
12 if (typeof opts.excerpt === 'function') {
13 return opts.excerpt(file, opts);
14 }
15
16 var sep = file.data.excerpt_separator || opts.excerpt_separator;
17 if (sep == null && (opts.excerpt === false || opts.excerpt == null)) {
18 return file;
19 }
20
21 var delimiter = sep || opts.delimiters[0];
22 if (typeof opts.excerpt === 'string') {
23 delimiter = opts.excerpt;
24 }
25
26 // if enabled, get the excerpt defined after front-matter
27 var idx = file.content.indexOf(delimiter);
28 if (idx !== -1) {
29 file.excerpt = file.content.slice(0, idx);
30 }
31
32 return file;
33};