forked from inclusive-design/wecount.inclusivedesign.ca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
140 lines (120 loc) · 4.44 KB
/
eleventy.config.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
/* global chunkArray, createPagination, getUniqueTags */
const errorOverlay = require("eleventy-plugin-error-overlay");
const pluginSass = require("eleventy-plugin-sass");
const pluginPWA = require("eleventy-plugin-pwa");
const fs = require("fs");
const dataFetcherWp = require("./src/utils/data-fetcher-wp.js");
const dataFetcherAirtable = require("./src/utils/data-fetcher-airtable.js");
const htmlMinifyTransform = require("./src/transforms/html-minify.js");
const parseTransform = require("./src/transforms/parse.js");
const dateFilter = require("./src/filters/date.js");
const htmlSymbolFilter = require("./src/filters/html-symbol.js");
const markdownFilter = require("./src/filters/markdown.js");
const w3DateFilter = require("./src/filters/w3-date.js");
const randomizeFilter = require("./src/filters/randomize.js");
require("./src/js/utils.js");
module.exports = function(eleventyConfig) {
// Use .eleventyignore instead of .gitignore.
eleventyConfig.setUseGitIgnore(false);
// Add custom collections.
eleventyConfig.addCollection("pages", async function() {
return dataFetcherWp.sitePages();
});
eleventyConfig.addCollection("workshops", async function() {
return dataFetcherAirtable.workshops();
});
eleventyConfig.addCollection("news", async function() {
return dataFetcherWp.categorizedItems("news", 8);
});
eleventyConfig.addCollection("views", async function() {
return dataFetcherWp.categorizedItems("views", 1);
});
eleventyConfig.addCollection("viewsTags", async function() {
const viewsPromise = dataFetcherWp.categorizedItems("views", 1);
return new Promise((resolve) => {
viewsPromise.then(views => {
resolve(getUniqueTags(views));
});
});
});
eleventyConfig.addCollection("tags", async function() {
const tags = await dataFetcherWp.siteTags();
const posts = await dataFetcherWp.sitePosts();
const pageSize = 10;
let collectionTogo = [];
tags.map(tag => {
const taggedPosts = posts.filter(post => {
const postTagSlugs = post.tags.map(({slug}) => slug);
return postTagSlugs.includes(tag.slug);
});
if (taggedPosts.length) {
const postsInPage = chunkArray(taggedPosts, pageSize);
for (let pageNumber = 1; pageNumber <= postsInPage.length; pageNumber++) {
let pagination;
if (pageNumber === 1) {
// Add the root page that has the same content as the first page
pagination = createPagination(taggedPosts, pageSize, 1, "/tags/" + tag.slug + "/page/:page");
collectionTogo.push({
slug: tag.slug,
title: tag.title,
posts: postsInPage[0],
pagination: pagination
});
}
collectionTogo.push({
slug: tag.slug,
title: tag.title,
pageNumber: pageNumber,
posts: postsInPage[pageNumber - 1],
pagination: pagination ? pagination : createPagination(taggedPosts, pageSize, pageNumber, "/tags/" + tag.slug + "/page/:page")
});
}
}
});
return collectionTogo;
});
// Add plugins.
eleventyConfig.addPlugin(errorOverlay);
eleventyConfig.addPlugin(pluginSass, {
watch: ["src/**/*.scss"],
sourcemaps: process.env.ELEVENTY_ENV === "development" ? true : false
});
eleventyConfig.addPlugin(pluginPWA);
// Add filters.
eleventyConfig.addFilter("dateFilter", dateFilter);
eleventyConfig.addFilter("htmlSymbolFilter", htmlSymbolFilter);
eleventyConfig.addFilter("markdownFilter", markdownFilter);
eleventyConfig.addFilter("w3DateFilter", w3DateFilter);
eleventyConfig.addFilter("randomizeFilter", randomizeFilter);
// Add transforms.
eleventyConfig.addTransform("htmlmin", htmlMinifyTransform);
eleventyConfig.addTransform("parse", parseTransform);
// Configure passthrough file copy.
eleventyConfig.addPassthroughCopy({"manifest.json": "manifest.json"});
eleventyConfig.addPassthroughCopy({"node_modules/infusion": "lib/infusion"});
eleventyConfig.addPassthroughCopy({"src/fonts": "fonts"});
eleventyConfig.addPassthroughCopy({"src/images": "images"});
eleventyConfig.addPassthroughCopy({"src/js": "js"});
// Configure BrowserSync.
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: (error, browserSync) => {
// TODO: Add custom 404 page.
const content404 = fs.readFileSync("dist/404.html");
// Provides the 404 content without redirect.
browserSync.addMiddleware("*", (request, response) => {
response.write(content404);
response.writeHead(404);
response.end();
});
}
}
});
return {
dir: {
input: "src",
output: "dist"
},
passthroughFileCopy: true
};
};