-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
183 lines (156 loc) · 5.6 KB
/
Copy path.eleventy.js
File metadata and controls
183 lines (156 loc) · 5.6 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// 11ty Plugins
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const eleventySass = require("@11tyrocks/eleventy-plugin-sass-lightningcss");
const eleventyGoogleFonts = require("eleventy-google-fonts");
// Helper packages
const slugify = require("slugify");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const VIP_BANNER_DEFAULTS = {
message:
"Join the VIP Club for early access, high-quality downloads and private chats with the residents.",
ctaText: "Join the VIP Club",
ctaHref: "https://housefinesse.com/club",
};
const escapeHtml = (value = "") =>
String(value)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">");
const escapeAttribute = (value = "") =>
escapeHtml(value).replace(/"/g, """);
const vipBannerShortcode = (
message = VIP_BANNER_DEFAULTS.message,
ctaText = VIP_BANNER_DEFAULTS.ctaText,
ctaHref = VIP_BANNER_DEFAULTS.ctaHref
) => {
const safeMessage =
typeof message === "string" && message.trim().length > 0
? escapeHtml(message)
: escapeHtml(VIP_BANNER_DEFAULTS.message);
const safeCtaText =
typeof ctaText === "string" && ctaText.trim().length > 0
? escapeHtml(ctaText)
: escapeHtml(VIP_BANNER_DEFAULTS.ctaText);
const safeCtaHref =
typeof ctaHref === "string" && ctaHref.trim().length > 0
? escapeAttribute(ctaHref)
: escapeAttribute(VIP_BANNER_DEFAULTS.ctaHref);
return `<aside class="vip-banner" aria-label="VIP Club promotion">
<div class="vip-banner__inner">
<p class="vip-banner__eyebrow">VIP Club</p>
<p class="vip-banner__message">${safeMessage}</p>
<a class="vip-banner__cta tdbc-button" href="${safeCtaHref}">${safeCtaText}</a>
</div>
</aside>`;
};
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(eleventySass);
// Disable Google Fonts fetching when running in offline environments
if (!process.env.ELEVENTY_OFFLINE) {
eleventyConfig.addPlugin(eleventyGoogleFonts);
}
eleventyConfig.addPassthroughCopy("./src/fonts");
eleventyConfig.addPassthroughCopy("./src/img");
eleventyConfig.addPassthroughCopy("./src/favicon.png");
eleventyConfig.addPassthroughCopy("./src/js");
eleventyConfig.addPassthroughCopy('./src/_redirects');
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
eleventyConfig.addShortcode("vipBanner", vipBannerShortcode);
eleventyConfig.addNunjucksShortcode("vipBanner", vipBannerShortcode);
eleventyConfig.addLiquidShortcode("vipBanner", vipBannerShortcode);
// Add a simple slugify filter for templates
eleventyConfig.addFilter('slugifyString', (value) =>
slugify(value || '', { lower: true, strict: true, remove: /["']/g })
);
eleventyConfig.addFilter('categoryFilter', function(collection, category) {
if (!category) return collection;
const filtered = collection.filter(item => item.data.category == category)
return filtered;
});
eleventyConfig.addFilter("formatDate", function (dateObj, format = "dd-LL-yyyy") {
if (!dateObj) {
return "";
}
const date = new Date(dateObj);
if (Number.isNaN(date.getTime())) {
return "";
}
const pad = (value) => String(value).padStart(2, "0");
const tokens = {
yyyy: String(date.getUTCFullYear()),
LL: pad(date.getUTCMonth() + 1),
dd: pad(date.getUTCDate()),
};
return format.replace(/yyyy|LL|dd/g, (token) => tokens[token] ?? token);
});
// ICS Calendar filters
eleventyConfig.addFilter('dateToRfc3339', function(date) {
return new Date(date).toISOString().replace(/[-:]/g, '').split('.')[0] + 'Z';
});
eleventyConfig.addFilter('escapeIcs', function(str) {
if (!str) return '';
return str
.replace(/\\/g, '\\\\')
.replace(/;/g, '\\;')
.replace(/,/g, '\\,')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/\t/g, '\\t');
});
eleventyConfig.addFilter('stripHtml', function(str) {
if (!str) return '';
return str.replace(/<[^>]*>/g, '').replace(/\s+/g, ' ').trim();
});
eleventyConfig.addFilter('webcalUrl', function(url) {
if (!url) return '';
return url.replace(/^https?:\/\//, '');
});
// Authors collection grouped by frontmatter `author`
eleventyConfig.addCollection('authors', (collectionApi) => {
const posts = collectionApi.getFilteredByTag('posts');
const authorToPosts = new Map();
for (const item of posts) {
const authorName = item.data.author;
if (!authorName) continue;
const normalizedName = String(authorName).trim();
const existingPosts = authorToPosts.get(normalizedName) || [];
existingPosts.push(item);
authorToPosts.set(normalizedName, existingPosts);
}
return Array.from(authorToPosts.entries())
.map(([name, items]) => ({
name,
slug: slugify(name, { lower: true, strict: true, remove: /["']/g }),
items,
}))
.sort((a, b) => a.name.localeCompare(b.name));
});
/* Markdown Overrides */
let markdownLibrary = markdownIt({
html: true,
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
class: "tdbc-anchor",
space: false,
}),
level: [1, 2, 3],
slugify: (str) =>
slugify(str, {
lower: true,
strict: true,
remove: /[""]/g,
}),
});
eleventyConfig.setLibrary("md", markdownLibrary);
return {
dir: {
input: "src",
output: "public",
layouts: "_layouts",
},
};
};