36 lines
No EOL
815 B
JavaScript
36 lines
No EOL
815 B
JavaScript
import * as path from 'node:path';
|
|
import * as fs from 'node:fs';
|
|
import exifr from 'exifr';
|
|
|
|
const conf = {
|
|
tags: "portfolio",
|
|
layout: "portfolio.njk",
|
|
eleventyComputed: {
|
|
async images(data) {
|
|
const dir = path.dirname(data.page.inputPath);
|
|
|
|
const files = fs.readdirSync(dir)
|
|
.filter(file => ['.png', '.jpg', '.jpeg', '.JPG'].includes(path.extname(file)))
|
|
.sort();
|
|
|
|
|
|
const images = await Promise.all(files.map(async (image) => {
|
|
|
|
const imagePath = path.resolve(dir + '/' + image);
|
|
const exif = await exifr.parse(imagePath, { pick: ['XPComment', 'DateTimeOriginal'] });
|
|
|
|
return {
|
|
url: data.page.url + image,
|
|
caption: exif?.XPComment ?? "",
|
|
date: exif?.DateTimeOriginal
|
|
};
|
|
|
|
}));
|
|
|
|
return images;
|
|
},
|
|
data(data) { return data; },
|
|
}
|
|
};
|
|
|
|
export default conf; |