-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
89 lines (80 loc) · 2.65 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
/**
* @file Configures preferences for Eleventy
* @author Andreas Pappas <andrewpap1997@gmail.com>
* @see {@link https://www.11ty.dev/docs/config/ 11ty Documentation}
*/
// Require native Node.js modules
import { readFileSync } from 'fs'
/**
* Require the includes module for the following.
*
* - Filters (for modifying content on input)
* - Shortcodes (for reusable content)
* - Transforms (for modifying a template’s output)
*
* Storing these modules in separate directories,
* rather than all in this file,
* helps keep the codebase organized—at least that’s the idea.
*/
import includes from './_includes/'
/**
* 11ty’s configuration module
* @module .eleventy
* @param {Object} eleventyConfig 11ty’s Config API
* @return {Object} 11ty’s Config object optional
* @see {@link https://www.11ty.dev/docs/config/ Configuring 11ty}
*/
export default function (eleventyConfig) {
// Pass 11ty’s Conig object to the includes module (~/_includes)
includes(eleventyConfig)
/**
* Combine data in the Eleventy data cascade, rather than overwriting it
* @see {@link https://www.11ty.dev/docs/data-deep-merge/ Data deep merge in 11ty}
*/
eleventyConfig.setDataDeepMerge(true)
/**
* Copy static assets to the output directory
* @see {@link https://www.11ty.dev/docs/copy/ Passthrough copy in 11ty}
*/
eleventyConfig.addPassthroughCopy('css')
/**
* Have Eleventy watch the following additional files for live browsersync
* @see @{@link https://www.11ty.dev/docs/config/#add-your-own-watch-targets Add your own watch targets in 11ty}
*/
eleventyConfig.addWatchTarget('./**/*.css')
eleventyConfig.addWatchTarget('./**/*.js')
/**
* Serve the rendered 404 page when using `eleventy --serve` locally
* @see {@link https://www.11ty.dev/docs/quicktips/not-found/#with-serve Adding a 404 page in 11ty}
*/
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: (err, bs) => {
bs.addMiddleware("*", (req, res) => {
const content_404 = readFileSync('_site/404.html');
// Provides the 404 content without redirect
res.write(content_404);
// Add 404 http status code in request header
// res.writeHead(404, { "Content-Type": "text/html" })
res.writeHead(404);
res.end()
})
}
}
})
// If you want to use an alternative file structure,
// then you can uncomment this return statement
// and change the values for one or more of these directories
// (defaults shown).
/*
return {
dir: {
input: '.',
includes: '_includes',
data: '_data',
output: '_site'
},
pathPrefix: '/',
}
*/
}