-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
95 lines (74 loc) · 3.16 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
const pluginRss = require('@11ty/eleventy-plugin-rss');
const pluginSyntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const { DateTime } = require('luxon');
const sass = require("sass");
module.exports = function (eleventyConfig) {
const markdownIt = require("markdown-it");
const markdownItFootnote = require("markdown-it-footnote");
const markdownLibrary = markdownIt().use(markdownItFootnote);
eleventyConfig.setLibrary("md", markdownLibrary);
// Values can be static:
eleventyConfig.addGlobalData("base", "https://michelenasti.com");
eleventyConfig.addGlobalData("sitename", "Michele Nasti");
eleventyConfig.addGlobalData("twitterName", "micnasti");
// Copy the `img` and `css` folders to the output
eleventyConfig.addPassthroughCopy('images');
eleventyConfig.addPassthroughCopy('uploads');
eleventyConfig.addPassthroughCopy('css');
eleventyConfig.addPassthroughCopy('archives');
eleventyConfig.addPassthroughCopy('favicon.ico');
eleventyConfig.addPassthroughCopy('scripts');
eleventyConfig.addPassthroughCopy('admin');
eleventyConfig.addTemplateFormats("scss");
// Add plugins
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.addFilter('postDate', (dateObj) => {
return DateTime.fromJSDate(dateObj)
.setLocale('en')
.toLocaleString(DateTime.DATE_FULL);
});
eleventyConfig.addFilter("imagePath", (path) => {
if (process.env.LOCAL) {
return path;
}
return `https://ik.imagekit.io/xthvogziier/tr:w-720/${path}`;
// to use netlify:
// return `https://michelenasti.com/.netlify/images?url=${path}&w=720`;
});
eleventyConfig.addFilter('toISODate', (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat("yyyy/MM/dd");
});
eleventyConfig.addFilter('sortObjectByKey', (collection) => {
const entries = Object.entries(collection);
const toReturn = entries.sort((entry1, entry2) => {
if (entry1[0] <= entry2[0]) return -1;
else return 1;
});
return toReturn;
});
// Creates the extension for use
eleventyConfig.addExtension("scss", {
outputFileExtension: "css", // optional, default: "html"
// `compile` is called once per .scss file in the input directory
compile: async function (inputContent) {
let result = sass.compileString(inputContent);
// This is the render function, `data` is the full data cascade
return async (data) => {
return result.css;
};
}
});
eleventyConfig.addCollection("posts", function (collectionApi) {
return collectionApi.getFilteredByGlob("_posts/**/*.md");
});
return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: ['md', 'njk', 'html'],
// Pre-process *.md files with: (default: `liquid`)
markdownTemplateEngine: 'njk',
// Pre-process *.html files with: (default: `liquid`)
htmlTemplateEngine: 'njk',
};
};