-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
91 lines (79 loc) · 2.82 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
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
const postcss = require("postcss");
const tailwindcss = require("tailwindcss");
const autoprefixer = require("autoprefixer");
const sharp = require("sharp");
const Image = require("@11ty/eleventy-img");
const { EleventyI18nPlugin } = require("@11ty/eleventy");
const GALLERY_IMAGE_WIDTH = 192;
const LANDSCAPE_LIGHTBOX_IMAGE_WIDTH = 2000;
const PORTRAIT_LIGHTBOX_IMAGE_WIDTH = 720;
// Credit https://www.bash.lk/posts/tech/1-elventy-image-gallery/
function galleryShortcode(content, name) {
return `
<div>
<script type="module">
import PhotoSwipeLightbox from '/js/photoswipe-lightbox.esm.min.js';
import PhotoSwipe from '/js/photoswipe.esm.min.js';
</script>
<div class="grid grid-cols-2 md:grid-cols-3 gap-2 items-center" id="gallery-${name}">
${content}
</div>
</div>
`.replace(/(\r\n|\n|\r)/gm, "");
}
async function galleryImageShortcode(src, alt) {
// const source = `./src${src}`;
// let lightboxImageWidth = LANDSCAPE_LIGHTBOX_IMAGE_WIDTH;
// const metadata = await sharp(source).metadata();
// if (metadata.height > metadata.width) {
// lightboxImageWidth = PORTRAIT_LIGHTBOX_IMAGE_WIDTH;
// }
// const options = {
// formats: ["jpeg"],
// widths: [GALLERY_IMAGE_WIDTH, lightboxImageWidth],
// urlPath: "./src/",
// outputDir: "./_site/img",
// };
// const genMetadata = await Image(source, options);
// console.log("genMetadata.jpeg", genMetadata.jpeg);
// <a href="${src}" data-pswp-width="1875" data-cropped="true"
// data-pswp-height="2500" >
// <img src="${src}"
// alt="${alt}" />
// </a>
return `
<a href="${src}" class="hover:shadow-md" >
<img src="${src}"
alt="${alt}" />
</a>
`.replace(/(\r\n|\n|\r)/gm, "");
}
module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(EleventyI18nPlugin, {
// any valid BCP 47-compatible language tag is supported
defaultLanguage: "en", // Required, this site uses "en"
// when normal use
errorMode: "allow-fallback", //"never", // // Opting out of "strict"
// when to build image
// errorMode: "never", //"never", // // Opting out of "strict"
});
eleventyConfig.addNunjucksAsyncFilter("postcss", (cssCode, done) => {
postcss([tailwindcss(require("./tailwind.config.js")), autoprefixer()])
.process(cssCode)
.then(
(r) => done(null, r.css),
(e) => done(e, null)
);
});
eleventyConfig.addWatchTarget("./src/**/*.css");
eleventyConfig.addPairedLiquidShortcode("gallery", galleryShortcode);
eleventyConfig.addLiquidShortcode("galleryImage", galleryImageShortcode);
eleventyConfig.addPassthroughCopy("js");
eleventyConfig.addPassthroughCopy("css");
return {
dir: {
input: "src",
output: "_site",
},
};
};