-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
71 lines (62 loc) · 2.56 KB
/
Copy path.eleventy.js
File metadata and controls
71 lines (62 loc) · 2.56 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
module.exports = function (eleventyConfig) {
// Static files:
// - `src/public` is copied to the site root (e.g. Google Search Console HTML verification)
// - `src/static` is copied under `/static/` (icons, misc files)
eleventyConfig.addPassthroughCopy({ 'src/public': '/' });
eleventyConfig.addPassthroughCopy({ 'src/static': '/static' });
eleventyConfig.addGlobalData('buildTime', () => new Date());
// Blog posts strictly from /src/blog (folder-based, not tag-based)
eleventyConfig.addCollection('blogPosts', (collectionApi) => {
// NOTE: In Eleventy v3, getFilteredByGlob is most reliable with a single glob string.
// We only treat markdown files in /src/blog as posts (avoids including blog/index.njk).
const items = collectionApi.getFilteredByGlob('./src/blog/**/*.md');
return items.sort((a, b) => a.date - b.date);
});
// Sitemap collection: only HTML pages, excluding anything opted-out via eleventyExcludeFromCollections
eleventyConfig.addCollection('sitemap', (collectionApi) => {
return collectionApi
.getAllSorted()
.filter((item) => !item.data?.eleventyExcludeFromCollections)
.filter((item) => typeof item.url === 'string' && typeof item.outputPath === 'string')
.filter((item) => item.outputPath.endsWith('.html'));
});
eleventyConfig.addFilter('dateISO', (value) => {
const d = value instanceof Date ? value : new Date(value);
return d.toISOString().slice(0, 10);
});
eleventyConfig.addFilter('dateSK', (value) => {
const d = value instanceof Date ? value : new Date(value);
return new Intl.DateTimeFormat('sk-SK', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
}).format(d);
});
eleventyConfig.addFilter('year', (value) => {
const d = value instanceof Date ? value : new Date(value);
return String(d.getFullYear());
});
// Array helper: take first N items (useful in Nunjucks where slice behaves differently)
eleventyConfig.addFilter('limit', (arr, n) => {
if (!Array.isArray(arr)) return [];
return arr.slice(0, n);
});
// Transform to ensure sitemap.xml starts with XML declaration (no leading whitespace)
eleventyConfig.addTransform('trimSitemap', function (content, outputPath) {
if (outputPath && outputPath.endsWith('/sitemap.xml')) {
return content.trimStart();
}
return content;
});
return {
dir: {
input: 'src',
includes: '_includes',
data: '_data',
output: '_site',
},
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
templateFormats: ['md', 'njk'],
};
};