|
|
@@ -38,12 +38,26 @@ eleventyConfig.addCollection("miniImages", function(collectionApi) {
|
|
|
const fullPath = path.join(dir, file);
|
|
|
if (fs.statSync(fullPath).isDirectory()) {
|
|
|
getFiles(fullPath);
|
|
|
- } else if (file.endsWith(".jpg") || file.endsWith(".jpeg")) {
|
|
|
+ } else if (file.endsWith(".jpg") ||
|
|
|
+ file.endsWith(".jpeg") ||
|
|
|
+ file.endsWith(".png")) {
|
|
|
+
|
|
|
+ // 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
|
|
|
- date: fs.statSync(fullPath).mtime
|
|
|
+ //album: dir.split(path.sep).pop(), // Gets the folder name
|
|
|
+ //breadcrumbs: pathParts,
|
|
|
+ //date: fs.statSync(fullPath).mtime
|
|
|
+ // ====================
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
@@ -53,11 +67,40 @@ eleventyConfig.addCollection("miniImages", function(collectionApi) {
|
|
|
|
|
|
// Group them by album name
|
|
|
const grouped = {};
|
|
|
+
|
|
|
files.forEach(f => {
|
|
|
- if (!grouped[f.album]) grouped[f.album] = [];
|
|
|
- grouped[f.album].push(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] = {
|
|
|
+ images: [],
|
|
|
+ subfolders: [],
|
|
|
+ breadcrumbArray: relFolder === "" ? [] : relFolder.split(path.sep)
|
|
|
+ //path: folderPath.split(path.sep) // Normalize to forward slashes
|
|
|
+ };
|
|
|
+ }
|
|
|
+ grouped[relFolder].images.push(f);
|
|
|
});
|
|
|
|
|
|
+ // Second pass to link parents to children subfolders
|
|
|
+ for (const parentPath in grouped) {
|
|
|
+ for (const potentialChild in grouped) {
|
|
|
+ const parentParts = parentPath === "" ? [] : parentPath.split(path.sep);
|
|
|
+ const childParts = potentialChild.split(path.sep);
|
|
|
+
|
|
|
+ // Is the child exactly one level deeper than the parent?
|
|
|
+ if (potentialChild.startsWith(parentPath) &&
|
|
|
+ childParts.length === parentParts.length + 1 &&
|
|
|
+ parentPath !== potentialChild) {
|
|
|
+ grouped[parentPath].subfolders.push(potentialChild);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return grouped;
|
|
|
});
|
|
|
// ========================================================
|