-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
112 lines (88 loc) · 2.72 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const {matter} = require('./pkg/');
console.log("################ TEST 0 ################");
console.log(`{
content: 'This is an excerpt.\n---\nThis is content',
data: { foo: 'bar' },
excerpt: 'This is an excerpt.\n'
}`);
console.log(matter(`---
foo: bar
---
This is an excerpt.
---
This is content`));
console.log("################ TEST 1 ################");
console.log(`{
content: 'This is content.',
data: { title: 'Front Matter' },
excerpt: ''
}`);
console.log(matter('---\ntitle: Front Matter\n---\nThis is content.'));
console.log("\n");
console.log("################ TEST 2 ################");
console.log(`{ content: 'Other stuff', data: { title: 'Home' }, excerpt: '' }`);
console.log(matter('---\ntitle: Home\n---\nOther stuff'));
console.log("\n");
const long_markdown = `---
title: "long form content"
description: "Front matter"
categories:
- "test"
- "categories"
---
Let's add an excerpt!
---
This is content`;
console.log("################ TEST 3 ################");
console.log(`{
content: '\nLet's add an excerpt!\n\n---\n\nThis is content',
data: {
title: 'long form content',
description: 'Front matter',
categories: [ 'test', 'categories' ]
}
excerpt: '\nLet's add an excerpt!\n\n'
}`);
console.log(matter(long_markdown));
console.log("\n");
data = matter(long_markdown);
console.log(data.data.title)
console.log("\n");
console.log("################ TEST 4 ################");
console.log(`{
content: 'this is an excerpt!\n\n---\n\nthis is content!',
data: {}
excerpt: 'this is an excerpt!\n\n'
}`);
console.log(matter("this is an excerpt!\n---\nthis is a content!"))
console.log("################ TEST 5 ################");
opt = {excerpt: true};
console.log(matter(long_markdown, opt));
console.log("should have excerpt!\n");
console.log(matter(long_markdown));
console.log("should not have excerpt!\n");
console.log("################ TEST 6 ################");
const long_markdown_different_separator = `---
title: "long form content"
description: "Front matter"
categories:
- "test"
- "categories"
---
Let's add an excerpt!
<!-- end -->
This is content`;
opt = {excerpt_separator: "<!-- end -->"};
console.log(matter(long_markdown_different_separator, opt));
console.log("should have excerpt!\n");
console.log(matter(long_markdown_different_separator, {excerpt: true, excerpt_separator: "<!-- end -->"}));
console.log("should have excerpt!\n");
console.log("################ TEST 7 ################");
const fun_markdown = `~~~
title: "fun markdown"
~~~
Content`;
console.log(matter(fun_markdown, {delimiters: "~~~"}));
console.log("should not have excerpt!\n");
console.log("################ TEST 8 ################");
console.log(matter("---\nfoo: bar\n---\ncontent", {bad: "data"}));