-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
102 lines (87 loc) · 2.18 KB
/
.eleventy.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
const markdownIt = require('markdown-it')({
html: true,
breaks: false,
linkify: true,
typographer: true
});
const formatDate = (date, format) => {
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];
const days = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
]
const m0 = date.getMonth();
const mm = `${m0 + 1}`.padStart(2, '0');
const MM = months[m0];
const M = MM.slice(0, 3);
const d = date.getDate();
const dd = `${d}`.padStart(2, '0');
const D = days[date.getDay()];
const yyyy = date.getFullYear();
const formats = {
'day': `${D}`,
'date': `${d}`,
'month': `${mm}`,
'month-name': `${MM}`,
'year': `${yyyy}`,
'numeric': `${mm}/${dd}/${yyyy}`,
'url': `${yyyy}/${mm}/${dd}`,
'short': `${M} ${d}, ${yyyy}`,
'long': `${MM} ${d}, ${yyyy}`,
}
return formats[format];
}
const getDate = (format = null, date = null) => {
const now = date ? new Date(date) : new Date();
return format ? formatDate(now, format) : now;
}
module.exports = (eleventyConfig) => {
eleventyConfig.addPassthroughCopy('assets');
eleventyConfig.addPassthroughCopy('CNAME');
eleventyConfig.addFilter("typeOf", (val) => {
return typeof val;
});
eleventyConfig.addFilter("formatDate", (date, format = 'short') => {
return formatDate(date, format);
});
eleventyConfig.addFilter("getDate", (date = null, format = 'short') => {
return getDate(format, date);
});
eleventyConfig.addFilter("md", (content, inline = false) => {
return inline
? markdownIt.renderInline(content)
: markdownIt.render(content);
});
eleventyConfig.addShortcode("getDate", (format = null) => {
return getDate(format);
});
eleventyConfig.addPairedShortcode("markdown", (content, inline = null) => {
return inline
? markdownIt.renderInline(content)
: markdownIt.render(content);
});
/* Markdown */
eleventyConfig.setLibrary('md', markdownIt);
return {
markdownTemplateEngine: "njk",
dir: { output: "docs" },
}
};