eleventy.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. module.exports = function(eleventyConfig) {
  2. const fs = require('fs');
  3. const path = require('path');
  4. // add my css file from the root folder
  5. eleventyConfig.addPassthroughCopy("bundle.css");
  6. eleventyConfig.addPassthroughCopy("img");
  7. eleventyConfig.addPassthroughCopy({ "_data/images": "photos" });
  8. // This line was to make sure my post.md weren't processed as Liquid,
  9. // permitting this post here
  10. eleventyConfig.setTemplateFormats(["md", "njk", "html"]);
  11. eleventyConfig.addGlobalData("site.author", "unakt");
  12. // Double with the .eleventyignore file, but just in case
  13. eleventyConfig.ignores.add("/_drafts/**");
  14. eleventyConfig.ignores.add("/README.md");
  15. eleventyConfig.addLayoutAlias("post", "post.njk");
  16. eleventyConfig.addCollection("postlist", function(collectionApi) {
  17. return collectionApi.getFilteredByGlob("./posts/*.md");
  18. });
  19. // Custom collection for mini images
  20. // It scans the ./src/_data/images/ folder for jpg files
  21. // and groups them by their parent folder name
  22. // Each image object contains its path, album name, and last modified date
  23. // ========================================================
  24. eleventyConfig.addCollection("miniImages", function(collectionApi) {
  25. const files = [];
  26. const baseDir = "./_data/images/";
  27. // Recursive function to find all jpgs
  28. const getFiles = (dir) => {
  29. fs.readdirSync(dir).forEach(file => {
  30. const fullPath = path.join(dir, file);
  31. if (fs.statSync(fullPath).isDirectory()) {
  32. getFiles(fullPath);
  33. } else if (file.endsWith(".jpg") || file.endsWith(".jpeg")) {
  34. const relativePath = path.relative("./_data/images", fullPath).replace(/\\/g, "/");
  35. files.push({
  36. path: "/photos/" + relativePath,
  37. album: dir.split(path.sep).pop(), // Gets the folder name
  38. date: fs.statSync(fullPath).mtime
  39. });
  40. }
  41. });
  42. };
  43. getFiles(baseDir);
  44. // Group them by album name
  45. const grouped = {};
  46. files.forEach(f => {
  47. if (!grouped[f.album]) grouped[f.album] = [];
  48. grouped[f.album].push(f);
  49. });
  50. return grouped;
  51. });
  52. // ========================================================
  53. // Date filter to format dates as YYYY-MM-DD
  54. eleventyConfig.addFilter("date", function(dateObj, format = "YYYY-MM-DD") {
  55. const d = new Date(dateObj);
  56. return d.toISOString().split('T')[0]; // Returns YYYY-MM-DD
  57. });
  58. return {
  59. // Ok idk this prevent markdown from being processed?
  60. markdownTemplateEngine: false,
  61. dir: {
  62. input: "./",
  63. output: "_site",
  64. layouts: "layouts",
  65. includes: "includes"
  66. }
  67. };
  68. };