-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
156 lines (133 loc) · 5.17 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const { DateTime } = require("luxon");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const Image = require("@11ty/eleventy-img");
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const CleanCSS = require("clean-css");
const sprite = require('./utils/sprite.js');
const shortcodes = require('./utils/shortcodes.js');
module.exports = function(eleventyConfig) {
// Add Plugins
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(eleventyNavigationPlugin);
// Filters
// VERSION
const currentVersion = 0.5;
eleventyConfig.addFilter("addVersion", function (string) {
return `${eleventyConfig.getFilter("slug")(string)}${currentVersion}`;
});
// Add version number to source URLs
eleventyConfig.addFilter("versionedURL", function (url) {
return `${eleventyConfig.getFilter("url")(url)}?v=${currentVersion}`;
});
// Concat and minify styles and inline to head.njk
eleventyConfig.addFilter("cssmin", function () {
const normalize = './src/assets/style/vendor/normalize.css';
const variables = './src/assets/style/tokens.css';
const fonts = './src/assets/style/fonts.css';
const base = './src/assets/style/base.css';
const typography = './src/assets/style/typography.css';
const head = './src/assets/style/head.css';
const cta = './src/assets/style/cta.css';
const layout = './src/assets/style/layout.css';
const navigation = './src/assets/style/navigation.css';
const forms = './src/assets/style/forms.css';
const blog = './src/assets/style/blog.css';
return new CleanCSS({ inline: ['local'] }).minify([normalize, variables, fonts, base, typography, head, cta, layout, navigation, forms, blog]).styles;
});
// Handle Images
eleventyConfig.addNunjucksAsyncShortcode("responsiveImage", async function (src, alt, sizes, realm) {
if (sizes === undefined) {
sizes = '(min-width: 30em) 50vw, 100vw';
} else {
sizes = sizes;
}
if (realm === 'hero') {
loadingKeyword = "eager";
} else {
loadingKeyword = "lazy";
}
// returns Promise
let metadata = await Image(src, {
formats: ["webp", "jpeg"],
// the directory in the image URLs <img src="/img/MY_IMAGE.png">
urlPath: "/assets/img/",
outputDir: "./dist/assets/img/",
widths: [640, 960, 1280, 1800, null]
});
let imageAttributes = {
alt,
sizes,
loading: loadingKeyword,
decoding: "async",
};
return Image.generateHTML(metadata, imageAttributes);
});
eleventyConfig.addNunjucksAsyncShortcode("handleOgImage", async function (src, alt) {
if (alt === undefined) {
// You bet we throw an error on missing alt (alt="" works okay)
throw new Error(`Missing \`alt\` on myImage from: ${src}`);
}
// returns Promise
let metadata = await Image(src, {
formats: ["jpeg"],
// the directory in the image URLs <img src="/img/MY_IMAGE.png">
urlPath: "/assets/img/",
outputDir: "./dist/assets/img/",
widths: [1200]
});
let data = metadata.jpeg[metadata.jpeg.length - 1];
let ogImagePath = "https://achteintel.org" + data.url;
return `<meta property="og:image" content="${ogImagePath}" /><meta property="og:image:type" content="image/jpeg" /><meta property="og:image:width" content="${data.width}" /><meta property="og:image:height" content="${data.height}" /><meta property="og:image:alt" content="${alt}" />`;
});
// Shortcodes
Object.keys(shortcodes).forEach((shortcodeName) => {
eleventyConfig.addShortcode(shortcodeName, shortcodes[shortcodeName])
})
// Symbols Sprite
eleventyConfig.addNunjucksAsyncShortcode('sprite', sprite)
// Asset Watch Targets
eleventyConfig.addWatchTarget('./src/assets')
// Use BrowserSync Watch Option
eleventyConfig.setBrowserSyncConfig({
watch: true
})
// Use luxon to generate readable date
eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate( new Date(dateObj) ).toFormat("dd.LL.yyyy");
});
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate( new Date(dateObj) ).toFormat('yyyy-LL-dd');
});
// Get the first `n` elements of a collection.
eleventyConfig.addFilter('head', (array, n) => {
if (n < 0) {
return array.slice(n);
}
return array.slice(0, n);
});
// Layouts
eleventyConfig.addLayoutAlias('base', 'base.njk')
eleventyConfig.addLayoutAlias('post', 'post.njk')
// Pass-through directories/files
eleventyConfig.addPassthroughCopy('src/assets/fonts')
eleventyConfig.addPassthroughCopy('src/assets/scripts')
eleventyConfig.addPassthroughCopy('src/assets/app-icons')
eleventyConfig.addPassthroughCopy('src/downloads')
eleventyConfig.addPassthroughCopy('src/manifest.json')
eleventyConfig.addPassthroughCopy('src/netlify.toml')
// Base Config
return {
dir: {
input: 'src',
output: 'dist',
includes: 'includes',
layouts: 'includes/layouts',
data: 'data'
},
templateFormats: ['njk', 'md'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
passthroughFileCopy: true
}
}