forked from Instawork/hyperview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
54 lines (53 loc) · 1.78 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
const {
sortCollectionFilter,
highlightFilter,
paginateFilter,
pageCountFilter,
} = require('./.eleventy/filters.js');
module.exports = function (eleventyConfig) {
eleventyConfig.setBrowserSyncConfig({
middleware: function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
res.setHeader(
'Access-Control-Allow-Headers',
'x-hyperview-dimensions,x-hyperview-version,pragma,expires,cache-control',
);
if (req.method === 'OPTIONS') {
res.writeHead(200, {});
res.end();
} else {
try {
const handler = require(`./examples${req._parsedUrl.pathname}.js`);
if (handler) {
handler(req, res, next);
} else {
// No handler found for route, pass through to 11ty
next();
}
} catch (err) {
// Error loading the handler, pass through to 11ty
next();
}
}
},
});
// Pass through any XML files that haven't been ported yet.
// Once everything is ported, we can remove this.
eleventyConfig.addPassthroughCopy('examples/**/*.xml');
// Pass through images used by different screens.
eleventyConfig.addPassthroughCopy('examples/**/*.jpg');
eleventyConfig.addPassthroughCopy('examples/**/*.jpeg');
eleventyConfig.addPassthroughCopy('examples/**/*.png');
// Add filters
eleventyConfig.addNunjucksFilter('sortCollection', sortCollectionFilter);
eleventyConfig.addNunjucksFilter('highlight', highlightFilter);
eleventyConfig.addNunjucksFilter('paginate', paginateFilter);
eleventyConfig.addNunjucksFilter('pageCount', pageCountFilter);
return {
dir: {
input: 'examples',
output: '_examples_site',
},
};
};