generated from fluid-project/trivet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
96 lines (77 loc) · 3.22 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
/*
Copyright the Trivet copyright holders.
See the AUTHORS.md file at the top-level directory of this distribution and at
https://github.com/fluid-project/trivet/raw/main/AUTHORS.md.
Licensed under the New BSD license. You may not use this file except in compliance with this License.
You may obtain a copy of the New BSD License at
https://github.com/fluid-project/trivet/raw/main/LICENSE.md.
*/
"use strict";
const fs = require("fs");
const fluidPlugin = require("eleventy-plugin-fluid");
const navigationPlugin = require("@11ty/eleventy-navigation");
const rssPlugin = require("@11ty/eleventy-plugin-rss");
const syntaxHighlightPlugin = require("@11ty/eleventy-plugin-syntaxhighlight");
// Import transforms
const htmlMinTransform = require("./src/transforms/html-min-transform.js");
const parseTransform = require("./src/transforms/parse-transform.js");
// Import data files
const siteConfig = require("./src/_data/config.json");
module.exports = function (config) {
config.setUseGitIgnore(false);
// Transforms
config.addTransform("htmlmin", htmlMinTransform);
config.addTransform("parse", parseTransform);
// Passthrough copy
config.addPassthroughCopy({"src/admin/config.yml": "admin/config.yml"});
config.addPassthroughCopy({"src/assets/icons": "/"});
config.addPassthroughCopy({"src/assets/images": "assets/images"});
config.addPassthroughCopy({"src/posts/images": "posts/images"});
const now = new Date();
// Custom collections
const livePosts = post => post.date <= now && !post.data.draft;
Object.keys(siteConfig.languages).forEach(lang => {
config.addCollection(`posts_${lang}`, collection => {
return collection.getFilteredByGlob(`./src/collections/posts/${lang}/*.md`).filter(livePosts);
});
// The following collection is used to create a collection of posts for the RSS feed.
config.addCollection(`postFeed_${lang}`, collection => {
return collection.getFilteredByGlob(`./src/collections/posts/${lang}/*.md`).filter(livePosts)
.reverse()
.slice(0, siteConfig.maxPostsInFeed);
});
});
// Plugins
config.addPlugin(fluidPlugin);
config.addPlugin(navigationPlugin);
config.addPlugin(rssPlugin);
config.addPlugin(syntaxHighlightPlugin);
// 404
config.setBrowserSyncConfig({
callbacks: {
ready: function (err, bs) {
bs.addMiddleware("*", (req, res) => {
const content_404 = fs.readFileSync("dist/404.html");
// Provides the 404 content without redirect.
res.write(content_404);
res.writeHead(404);
res.end();
});
}
}
});
config.on("beforeBuild", () => {
if (!siteConfig.languages[siteConfig.defaultLanguage]) {
process.exitCode = 1;
throw new Error(`The default language, ${siteConfig.defaultLanguage}, configured in src/_data/config.json is not one of your site's supported languages.`);
}
});
return {
dir: {
input: "src",
output: "dist",
includes: "_includes"
},
passthroughFileCopy: true
};
};