forked from geomedialab/atlascine-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
74 lines (71 loc) · 2.58 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
// Import prior to `module.exports` within `.eleventy.js`
const { DateTime } = require("luxon");
/*
const markdownIt = require('markdown-it');
const markdownItReplaceLink = require('markdown-it-replace-link');
*/
module.exports = function (eleventyConfig) {
/*
// https://www.npmjs.com/package/markdown-it-replace-link
eleventyConfig.setLibrary('md', markdownIt({
html: true,
linkify: true
}).use(markdownItReplaceLink, {
processHTML: true, // defaults to false for backwards compatibility
replaceLink: function (link, env, token, htmlToken) {
return "https://atlascine.org/en/" + link;//incomplete, need to integrate language dynamically
}
}));
*/
eleventyConfig.addFilter("formatDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toISODate();
});
eleventyConfig.addPassthroughCopy("src/imgs/");//add folders to public
eleventyConfig.addPassthroughCopy("src/js/");
eleventyConfig.addPassthroughCopy("CNAME");
eleventyConfig.addPassthroughCopy({ "en/index.md": "/index.md" });
//eleventyConfig.addGlobalData("langs", ['en', 'fr']);
eleventyConfig.addCollection("en", function (collection) {
return collection.getFilteredByGlob("./src/en/**/*.+(md|njk)");
});
eleventyConfig.addCollection("fr", function (collection) {
return collection.getFilteredByGlob("./src/fr/**/*.+(md|njk)");
});
//following snippet from https://cfjedimaster.github.io/eleventy-blog-guide/guide.html
eleventyConfig.addShortcode('excerpt', post => extractExcerpt(post));
function extractExcerpt(post) {
if(!post.templateContent) return '';
if(post.templateContent.indexOf('</p>') > 0) {
let end = post.templateContent.indexOf('</p>');
return post.templateContent.substr(0, end);
}
return post.templateContent;
}
// Custom data function to set the buildTime
eleventyConfig.addGlobalData('buildTime', () => {
return new Date().toISOString().slice(0, 10);
});
eleventyConfig.addFilter('main', (content) => {
const separator = '<!--section-->';
const parts = content.split(separator);
return parts[0];
});
eleventyConfig.addFilter('sidenote', (content) => {
const separator = '<!--section-->';
const parts = content.split(separator);
return parts[1];
});
return {
dir: {
input: 'src',
includes: '_includes',
layouts: '_layouts',
data: '_data',
output: 'public',
},
templateFormats: ['html', 'md', 'njk','css'],//copy any files with these extensions to _site
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
dataTemplateEngine: 'njk'
};
};