This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
47 lines (43 loc) · 1.67 KB
/
.eleventy.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
const lazyImagesPlugin = require("eleventy-plugin-lazyimages");
const eleventyPluginFilesMinifier = require("@sherby/eleventy-plugin-files-minifier");
const eleventyPluginFeathericons = require('eleventy-plugin-feathericons');
const { execSync } = require('child_process')
module.exports = function (eleventyConfig) {
// change this rootURL with your domain (without / at the end, see my example) !important
eleventyConfig.addGlobalData("rootURL", "https://eleventy-card.netlify.app");
eleventyConfig.on('eleventy.after', () => {
execSync(`npx -y pagefind --site _site --output-subdir _pagefind`, { encoding: 'utf-8' })
})
eleventyConfig.addPlugin(lazyImagesPlugin);
eleventyConfig.addPlugin(eleventyPluginFilesMinifier);
eleventyConfig.addPlugin(eleventyPluginFeathericons);
eleventyConfig.addPassthroughCopy("asset");
eleventyConfig.addPassthroughCopy("robots.txt");
// Collection post blog
eleventyConfig.addCollection("posts", function (collectionApi) {
return collectionApi.getFilteredByGlob("blog/**/*.md");
});
// Collection post photos
eleventyConfig.addCollection("photos", function (collectionApi) {
return collectionApi.getFilteredByGlob("photos/**/*.md");
});
// Collection tags thanks chatgpt
eleventyConfig.addCollection("blogTags", getTags("blog"));
eleventyConfig.addCollection("photosTags", getTags("photos"));
};
/**
* @param {'blog'|'photos'} type
*/
function getTags(type) {
return (collection) => {
let tagsSet = new Set();
collection.getAll().forEach((item) => {
if (item.filePathStem.includes(`/${type}/`) && item.data.tags) {
item.data.tags.forEach((tag) => {
tagsSet.add(tag);
});
}
});
return Array.from(tagsSet);
};
}