-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheleventy.config.js
More file actions
206 lines (162 loc) · 4.82 KB
/
Copy patheleventy.config.js
File metadata and controls
206 lines (162 loc) · 4.82 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { EleventyI18nPlugin } from "@11ty/eleventy";
import tocPlugin from "eleventy-plugin-toc";
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import htmlTransform from './transforms/htmlTransform.js';
import details from './shortcodes/details.js';
const mdOptions = {
html: true,
breaks: true,
}
const mdAnchorOpts = {
// permalink: markdownItAnchor.permalink.linkAfterHeader({
// class: 'anchor-link',
// style: 'visually-hidden',
// symbol: '#',
// }),
level: [1, 2, 3, 4]
}
// Full locale codes are required in Open Graph locale tags
const locales = {
"en": "en-GB",
"es": "es-ES",
};
function translateURL(URL, lang) {
let newURL = "/";
let splitURL = URL.split('/')
if (lang == "es") {
newURL += "es/";
if (URL.includes("/blog/")) {
newURL += "blog/";
if (splitURL.at(-2) != "blog") {
let year = splitURL.at(-3);
let post = splitURL.at(-2);
let translatedPost;
if (post == "pronouns" ) {
translatedPost = "pronombres";
}
else if (post == "microsoft-office-is-still-bad" ) {
translatedPost = "microsoft-office-sigue-siendo-malo";
}
if (translatedPost) {
newURL += year + "/" + translatedPost + "/";
}
//If an article is not translated, goes to blog page
}
} else if (URL.includes("/living-pages/")) {
newURL += "paginas-vivas/";
// Disabled as there's currently no translated living pages
// if (splitURL.at(-2) != "living-pages") {
// let page = splitURL.at(-2);
// let translatedPage;
// // Work out translated page names here
// if (translatedPage) {
// newURL += translatedPage;
// }
// //If a living-page is not translated, goes to living pages page.
// }
} else if (URL.includes("/about-this-site/")) {
newURL += "sobre-esta-web/";
} else { //Assumes that other top-level pages have the same name (eg homepage)
newURL = "/es" + URL;
}
} else if (lang == "en" ) {
if (URL.includes("/blog/")) {
newURL += "blog/";
if (splitURL.at(-2) != "blog") {
let year = splitURL.at(-3);
let post = splitURL.at(-2);
let translatedPost;
if (post == "pronombres" ) {
translatedPost = "pronouns";
}
else if (post == "microsoft-office-sigue-siendo-malo" ) {
translatedPost = "microsoft-office-is-still-bad";
}
if (translatedPost) {
newURL += year + "/" + translatedPost + "/";
}
}
} else if (URL.includes("/paginas-vivas/")) {
newURL += "living-pages/";
// Disabled as there's currently no translated living pages
// if (splitURL.at(-2) != "paginas-vivas") {
// let page = splitURL.at(-2);
// let translatedPage;
// if (translatedPage) {
// newURL += translatedPage;
// }
// }
} else if (URL.includes("/sobre-esta-web/")) {
newURL += "about-this-site/";
} else {
newURL += splitURL.at(2);
}
}
return newURL;
};
export default function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("stylesheets/");
eleventyConfig.addPassthroughCopy("_redirects");
eleventyConfig.addPassthroughCopy("favicon.ico");
eleventyConfig.addPassthroughCopy("manifest.json");
eleventyConfig.addPassthroughCopy("es/manifest.json");
eleventyConfig.addTemplateFormats([ //Using glob passthroughs doesn't work. When building for the second time, it creates a _site folder under _site, which breaks file location references
"xml",
"svg",
"webp",
"jxl",
"avif",
"jpg",
"opus",
// "png"
]);
// Transforms
eleventyConfig.addTransform('html', htmlTransform());
eleventyConfig.setLibrary(
'md',
markdownIt(mdOptions).use(markdownItAnchor, mdAnchorOpts)
)
// Shortcodes
eleventyConfig.addPairedShortcode('details', details);
// Plugins
eleventyConfig.addPlugin(EleventyI18nPlugin,{
defaultLanguage: "en",
});
eleventyConfig.addPlugin(tocPlugin, {
tags: ['h2', 'h3', 'h4'],
ul: true,
});
// Filters
eleventyConfig.addFilter("postDate", (date, lang) => {
if (lang == "en") {
lang = "en-GB";
}
const dateObj = new Date(date)
return dateObj.toLocaleString(lang, {dateStyle: "long", timeZone: "Europe/London"});
});
eleventyConfig.addFilter("ISOTime", (dateObj) => {
return dateObj.toISOString();
});
// Takes a default English language URL and converts it to the specified language
eleventyConfig.addFilter("localiseURL", (URL, lang) => {
if (lang == "en" ) {
return URL;
} else {
return translateURL(URL, lang);
}
});
//Converts the current URL to the specified language
eleventyConfig.addFilter("translateURL", (URL, lang) => {
return translateURL(URL, lang);
});
eleventyConfig.addFilter("get_introduction", (content) => {
return content.split('%contents%')[0]
});
eleventyConfig.addFilter("get_content", (content) => {
return content.split('%contents%')[1]
});
eleventyConfig.addFilter("localeCode", (lang) => {
return locales[lang];
});
};