-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
executable file
·76 lines (60 loc) · 2.59 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
const eleventyNavigationPlugin = require('@11ty/eleventy-navigation');
const lazyImagesPlugin = require('eleventy-plugin-lazyimages');
const config = require('./src/_data/config.json');
const locale = require('./src/_data/locale.json');
function getDescendantProp(obj, desc) {
const arr = desc.split('.');
while (arr.length && (obj = obj[arr.shift()]));
return obj;
}
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({ 'src/favicon': '/' });
eleventyConfig.addPassthroughCopy('src/images');
eleventyConfig.addPassthroughCopy('src/webfonts');
eleventyConfig.addPassthroughCopy({
'node_modules/mapbox-gl/dist/mapbox-gl.css': 'styles/mapbox-gl.css',
});
// lightgallery
eleventyConfig.addPassthroughCopy({
'node_modules/lightgallery.js/dist/css/lightgallery.min.css': 'styles/lightgallery.min.css',
});
eleventyConfig.addPassthroughCopy({ 'node_modules/lightgallery.js/dist/img': 'img' });
eleventyConfig.addPassthroughCopy({ 'node_modules/lightgallery.js/dist/fonts': 'fonts' });
eleventyConfig.addPassthroughCopy('src/scripts/jquery-3.1.1.min.js');
eleventyConfig.addPassthroughCopy('src/scripts/bootstrap.bundle.min.js');
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(lazyImagesPlugin, {
imgSelector: '.gallery img, #prints img, #map-wc-content img',
preferNativeLazyLoad: false,
transformImgPath: (imgPath) => {
if (imgPath.startsWith('/') && !imgPath.startsWith('//')) {
return `./src${imgPath}`;
}
return imgPath;
},
});
eleventyConfig.addNunjucksFilter('isActivePage', function (navPage, page) {
return (
navPage.url === page.url ||
(navPage.children.length && navPage.children.some((p) => p.url === page.url))
);
});
eleventyConfig.addNunjucksShortcode('defaultLocale', function (config, locale, key) {
return getDescendantProp(locale[config.defaultLocale], key);
});
eleventyConfig.addHandlebarsShortcode('defaultLocale', function (key) {
return getDescendantProp(locale[config.defaultLocale], key);
});
// new function that also wraps the text
eleventyConfig.addHandlebarsShortcode('locale', function (key) {
const text = getDescendantProp(locale[config.defaultLocale], key);
return `<span class="js-lcl" data-lcl="${key}">${text}</span>`;
});
eleventyConfig.addHandlebarsShortcode('arr', (...args) => args.slice(0, -1));
return {
dir: { input: 'src', output: 'dist', data: '_data' },
passthroughFileCopy: true,
templateFormats: ['hbs', 'njk', 'md', 'css', 'html', 'yml'],
htmlTemplateEngine: 'njk',
};
};