|
|
@@ -2,6 +2,7 @@ module.exports = function(eleventyConfig) {
|
|
|
|
|
|
const fs = require('fs');
|
|
|
const path = require('path');
|
|
|
+const exifParser = require("exif-parser");
|
|
|
|
|
|
// add my css file from the root folder
|
|
|
eleventyConfig.addPassthroughCopy("bundle.css");
|
|
|
@@ -34,30 +35,50 @@ eleventyConfig.addCollection("miniImages", function(collectionApi) {
|
|
|
|
|
|
// Recursive function to find all jpgs
|
|
|
const getFiles = (dir) => {
|
|
|
+ if (!fs.existsSync(dir)) return; // [EXIF] Safety check
|
|
|
fs.readdirSync(dir).forEach(file => {
|
|
|
const fullPath = path.join(dir, file);
|
|
|
if (fs.statSync(fullPath).isDirectory()) {
|
|
|
getFiles(fullPath);
|
|
|
} else if (file.endsWith(".jpg") ||
|
|
|
file.endsWith(".jpeg") ||
|
|
|
- file.endsWith(".png")) {
|
|
|
+ file.endsWith(".png") ||
|
|
|
+ file.endsWith(".gif") ||
|
|
|
+ file.endsWith(".webp")) {
|
|
|
+ // .jpg an others extensions might be case sensitive on some systems !!
|
|
|
|
|
|
+ // READ EXIF DATA
|
|
|
+ let exifData = {};
|
|
|
+ try {
|
|
|
+ const buffer = fs.readFileSync(fullPath);
|
|
|
+ const parser = exifParser.create(buffer);
|
|
|
+ const result = parser.parse();
|
|
|
+
|
|
|
+ exifData = {
|
|
|
+ model: result.tags.Model || "Unknown Camera",
|
|
|
+ lens: result.tags.LensModel || "Unknown Lens",
|
|
|
+ focalLength: result.tags.FocalLength ? `${result.tags.FocalLength}` : "N/A",
|
|
|
+ fNumber: result.tags.FNumber ? `f/${result.tags.FNumber}` : "N/A",
|
|
|
+ exposure: result.tags.ExposureTime ? `1/${Math.round(1/result.tags.ExposureTime)}s` : "N/A",
|
|
|
+ iso: result.tags.ISO || "N/A"
|
|
|
+ };
|
|
|
+ } catch (e) {
|
|
|
+ console.error(`Could not parse EXIF for ${file}:`, e.message);
|
|
|
+ }
|
|
|
+ // END READ EXIF DATA
|
|
|
+
|
|
|
// BEFORE =============
|
|
|
const relativePath = path.relative("./_data/images", fullPath).replace(/\\/g, "/");
|
|
|
//const pathParts = relativePath.split(path.sep).slice(0, -1); // Make Breadcrumb
|
|
|
// ====================
|
|
|
|
|
|
files.push({
|
|
|
- // AFTER ==============
|
|
|
fullPath: fullPath, // We need this for the calculation below
|
|
|
//webPath: fullPath.replace("src/", "/"),
|
|
|
date: fs.statSync(fullPath).mtime,
|
|
|
- // BEFORE =============
|
|
|
path: "/photos/" + relativePath,
|
|
|
- //album: dir.split(path.sep).pop(), // Gets the folder name
|
|
|
- //breadcrumbs: pathParts,
|
|
|
- //date: fs.statSync(fullPath).mtime
|
|
|
- // ====================
|
|
|
+ folderPath: path.relative(baseDir, path.dirname(fullPath)),
|
|
|
+ exif: exifData,
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
@@ -69,12 +90,7 @@ eleventyConfig.addCollection("miniImages", function(collectionApi) {
|
|
|
const grouped = {};
|
|
|
|
|
|
files.forEach(f => {
|
|
|
- // AFTER ==============
|
|
|
const relFolder = path.relative(baseDir, path.dirname(f.fullPath));
|
|
|
- // BEFORE =============
|
|
|
- // Use the directory path as the unique ID (e.g., "wargaming/40k/orks")
|
|
|
- //const folderPath = path.dirname(path.relative("./_data/images", f.path));
|
|
|
-
|
|
|
|
|
|
if (!grouped[relFolder]) {
|
|
|
grouped[relFolder] = {
|
|
|
@@ -102,14 +118,35 @@ eleventyConfig.addCollection("miniImages", function(collectionApi) {
|
|
|
}
|
|
|
}
|
|
|
return grouped;
|
|
|
- });
|
|
|
+});
|
|
|
// ========================================================
|
|
|
|
|
|
+eleventyConfig.addCollection("allPhotos", function(collectionApi) {
|
|
|
+ //const grouped = collectionApi.getFilteredByTag("miniImages"); // This won't work since miniImages isn't a tag
|
|
|
+ // Instead, use the logic we already built:
|
|
|
+ const miniImages = collectionApi.getAll()[0].data.collections.miniImages;
|
|
|
+
|
|
|
+ return Object.values(miniImages).flatMap(album => album.images);
|
|
|
+});
|
|
|
+
|
|
|
// Date filter to format dates as YYYY-MM-DD
|
|
|
-eleventyConfig.addFilter("date", function(dateObj, format = "YYYY-MM-DD") {
|
|
|
- const d = new Date(dateObj);
|
|
|
- return d.toISOString().split('T')[0]; // Returns YYYY-MM-DD
|
|
|
- });
|
|
|
+//eleventyConfig.addFilter("date", function(dateObj, format = "YYYY-MM-DD") {
|
|
|
+// const d = new Date(dateObj);
|
|
|
+// return d.toISOString().split('T')[0]; // Returns YYYY-MM-DD
|
|
|
+// });
|
|
|
+
|
|
|
+eleventyConfig.addFilter("date", function(dateObj) {
|
|
|
+ const d = new Date(dateObj);
|
|
|
+
|
|
|
+ // Check if the date is actually valid
|
|
|
+ if (isNaN(d.getTime())) {
|
|
|
+ console.warn("Skipping invalid date for a file. Value received:", dateObj);
|
|
|
+ return "Date Unknown";
|
|
|
+ }
|
|
|
+
|
|
|
+ return d.toISOString().split('T')[0];
|
|
|
+});
|
|
|
+
|
|
|
|
|
|
return {
|
|
|
// Ok idk this prevent markdown from being processed?
|