-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
147 lines (135 loc) · 4.7 KB
/
Copy path.eleventy.js
File metadata and controls
147 lines (135 loc) · 4.7 KB
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
// ABOUTME: Eleventy configuration for dylanreed.com author site.
// ABOUTME: Configures input/output dirs, passthrough copies, custom filters, and book page generation.
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("src/assets/css");
eleventyConfig.addPassthroughCopy("src/assets/images");
eleventyConfig.addPassthroughCopy("src/assets/fonts");
eleventyConfig.addPassthroughCopy("src/assets/downloads");
eleventyConfig.addFilter("date", (value, format) => {
const d = value ? new Date(value) : new Date();
if (format === "Y") return d.getFullYear().toString();
if (format === "MMMM D, YYYY") {
return d.toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" });
}
return d.toISOString();
});
eleventyConfig.addFilter("genreColor", (genre) => {
const colors = {
"Cozy Fantasy": "#6b8e6b",
"Sci-Fi": "#4a7a8b",
"Romance": "#b5566a",
"Steampunk": "#b8860b",
"Urban Fantasy": "#7b68ae",
"Noir": "#555555",
"Space Western": "#c9784c",
"YA Superhero": "#e06040"
};
return colors[genre] || "#8b7355";
});
eleventyConfig.addFilter("titleHash", (title) => {
let hash = 0;
for (let i = 0; i < title.length; i++) {
hash = ((hash << 5) - hash) + title.charCodeAt(i);
hash = hash & hash;
}
hash = Math.abs(hash);
const noteRotation = (hash % 60 - 30) / 10;
const tape1Rotation = ((hash >> 4) % 50 - 25);
const tape2Rotation = ((hash >> 8) % 50 - 25);
const tape1Width = 42 + ((hash >> 12) % 13);
const tape2Width = 42 + ((hash >> 16) % 13);
const tape1Top = -3 - ((hash >> 3) % 4);
const tape1Side = -5 - ((hash >> 7) % 6);
const tape2Bottom = -3 - ((hash >> 11) % 4);
const tape2Side = -5 - ((hash >> 15) % 6);
const mirrorCorners = (hash % 2 === 0);
return {
noteRotation,
tape1Rotation: mirrorCorners ? tape1Rotation : -tape1Rotation,
tape2Rotation: mirrorCorners ? tape2Rotation : -tape2Rotation,
tape1Width,
tape2Width,
tape1Top,
tape1Side: mirrorCorners ? `left: ${tape1Side}px` : `right: ${tape1Side}px`,
tape2Bottom,
tape2Side: mirrorCorners ? `right: ${tape2Side}px` : `left: ${tape2Side}px`
};
});
eleventyConfig.addFilter("statusLabel", (status) => {
const labels = {
"published": "published",
"submitted": "submitted",
"available-soon": "available soon",
"in-revision": "in revision",
"in-progress": "in progress",
"drafting": "drafting",
"first draft complete": "first draft complete",
"editing": "editing"
};
return labels[status] || status;
});
eleventyConfig.addCollection("bookPages", function(collectionApi) {
try {
const books = require("./src/_data/books.json");
return books;
} catch (e) {
return [];
}
});
// Generate individual book pages from books.json
try {
delete require.cache[require.resolve("./src/_data/books.json")];
const books = require("./src/_data/books.json");
books.forEach(book => {
eleventyConfig.addTemplate(`books/${book.slug}.njk`, `---
layout: layouts/book.njk
title: "${book.title}"
genre: "${book.genre}"
series: ${book.series ? '"' + book.series + '"' : "null"}
status: "${book.status}"
wordCount: ${book.wordCount || 0}
universe: ${book.universe ? '"' + book.universe + '"' : "null"}
purchaseLink: ${book.purchaseLink ? '"' + book.purchaseLink + '"' : "null"}
coverImage: ${book.coverImage ? '"' + book.coverImage + '"' : "null"}
freeWithNewsletter: ${book.freeWithNewsletter ? "true" : "false"}
permalink: /books/${book.slug}/
---
${book.blurb}`);
});
} catch(e) {
// books.json may not exist yet
}
// Generate individual universe pages from universes.json
try {
delete require.cache[require.resolve("./src/_data/universes.json")];
delete require.cache[require.resolve("./src/_data/books.json")];
const universes = require("./src/_data/universes.json");
const books = require("./src/_data/books.json");
universes.forEach(universe => {
const hasBooks = books.some(b => b.universe === universe.id);
if (hasBooks) {
eleventyConfig.addTemplate(`books/${universe.id}.njk`, `---
layout: layouts/universe.njk
title: "${universe.name}"
universeName: "${universe.name}"
universeId: "${universe.id}"
universeDescription: "${universe.description.replace(/"/g, '\\"')}"
genre: "${universe.genre}"
permalink: /books/${universe.id}/
---`);
}
});
} catch(e) {
// universes.json may not exist yet
}
return {
dir: {
input: "src",
output: "_site",
includes: "_includes",
data: "_data"
},
templateFormats: ["njk", "html"],
htmlTemplateEngine: "njk"
};
};