-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
86 lines (77 loc) · 2.39 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
// Make `.env` key-value available to Eleventy
require('dotenv').config();
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy('src/assets');
/**
* Eleventy Filter: `ago`
* ======================
* Takes a string and uses moment to format it into a new string
* based on the 'x days ago' format
*
* @docs https://momentjs.com/docs/#/displaying/fromnow/
*
* @param { String } date
* @return { String }
*/
eleventyConfig.addFilter('ago', function(date) {
const moment = require('moment');
return moment(date).fromNow();
});
/**
* Eleventy Filter: `date`
* =======================
* Takes a string and uses moment to format it into a new string
* second parameter sets date format; See moment docs for more info
*
* @docs https://momentjs.com/docs/#/parsing/string-format/
*
* @param { String } date
* @param { String } format
* @return { String }
*/
eleventyConfig.addFilter('date', function(date, format) {
const moment = require('moment');
return (format) ? moment(date).format(format) : moment(date).format("MMMM Do, YYYY");
});
/**
* Eleventy Filter: sort_array
* ===========================
* Sorts an array of objects/arrays and sorts them by a particular
* property. See `base.njk` for an example use sorting pages by title
* for the navigation.
*
* @docs https://lodash.com/docs/#orderBy
*
* @param { Array } array to be sorted, i.e., the filtered 11ty object
* @param { String } path or property to be sorted by
* @param { String } order direction i.e., `asc` or `desc`
*
* @return { Array }
*/
eleventyConfig.addFilter('sort_array', function(array, path, order) {
const orderBy = require('lodash/orderBy');
return orderBy(array, path, order);
});
/**
* Eleventy Plugin: Local Images
* =============================
* Makes an async request to download images locally at build time.
*
* Intended to be used in conjunction with Netlify, to take advantage
* of its default CDN. If you use a CDN with WordPress already,
* disable this plugin.
*/
const localImages = require('eleventy-plugin-local-images');
eleventyConfig.addPlugin(localImages, {
distPath: 'build',
assetPath: '/assets/img',
selector: 'img',
verbose: true
});
return {
dir: {
input: "src",
output: "build"
}
}
}