| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- module.exports = function(eleventyConfig) {
- const fs = require('fs');
- const path = require('path');
- // add my css file from the root folder
- eleventyConfig.addPassthroughCopy("bundle.css");
- eleventyConfig.addPassthroughCopy("img");
- eleventyConfig.addPassthroughCopy({ "_data/images": "photos" });
- // This line was to make sure my post.md weren't processed as Liquid,
- // permitting this post here
- eleventyConfig.setTemplateFormats(["md", "njk", "html"]);
- eleventyConfig.addGlobalData("site.author", "unakt");
- // Double with the .eleventyignore file, but just in case
- eleventyConfig.ignores.add("/_drafts/**");
- eleventyConfig.ignores.add("/README.md");
- eleventyConfig.addLayoutAlias("post", "post.njk");
- eleventyConfig.addCollection("postlist", function(collectionApi) {
- return collectionApi.getFilteredByGlob("./posts/*.md");
- });
- // Custom collection for mini images
- // It scans the ./src/_data/images/ folder for jpg files
- // and groups them by their parent folder name
- // Each image object contains its path, album name, and last modified date
- // ========================================================
- eleventyConfig.addCollection("miniImages", function(collectionApi) {
- const files = [];
- const baseDir = "./_data/images/";
- // Recursive function to find all jpgs
- const getFiles = (dir) => {
- 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")) {
-
- // 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
- // ====================
- });
- }
- });
- };
- getFiles(baseDir);
-
- // Group them by album name
- 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] = {
- 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;
- });
- // ========================================================
- // 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
- });
- return {
- // Ok idk this prevent markdown from being processed?
- markdownTemplateEngine: false,
- dir: {
- input: "./",
- output: "_site",
- layouts: "layouts",
- includes: "includes"
- }
- };
- };
|