-
-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathexcerpt.js
More file actions
36 lines (30 loc) · 741 Bytes
/
excerpt.js
File metadata and controls
36 lines (30 loc) · 741 Bytes
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
const matter = require('..');
const green = require('ansi-green');
// excerpt as a boolean
const file1 = matter([
'---',
'foo: bar',
'---',
'This is an excerpt.',
'---',
'This is content'
].join('\n'), {excerpt: true});
console.log(green('/* excerpt: true */'));
console.log(file1);
// excerpt as a function
// returns the first 4 lines of the contents
function firstFourLines(file, options) {
file.excerpt = file.content.split('\n').slice(0, 4).join(' ');
}
const file2 = matter([
'---',
'foo: bar',
'---',
'Only this',
'will be',
'in the',
'excerpt',
'but not this...'
].join('\n'), { excerpt: firstFourLines });
console.log(green('/* excerpt: function(file, options) { ... } */'));
console.log(file2);