Getting image path from 11tydata in a folder for 11ty image plugin
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 467
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
So, I'd like to keep images seperated by collectionGlob. Each collection has an image folder. When calling a nunjucks plugin to process the image, I'd like it to tell the folder path + src. That I would like to come from a folder data file either json or js. Just unsure how to go about doing it?
in _11ty/image.js
const Image = require("@11ty/eleventy-img");
const path = require("path");
const fs = require("fs");
module.exports = function(src, alt, widths, sizes, classattr) {
// src input same as 'normal' site-relative path for convenience, so add base path:
src = collectionpath + src;
let ext = src.substr(src.lastIndexOf(".") + 1);
let currentFormat = ext == "png" ? "png" : "jpeg";
let srcset = [100, 320, 640, 1024, 1536, 2048];
if (widths) {
widthsArray = widths.split(",");
srcset = widthsArray.map(n => Number(n));
}
let options = {
urlPath: collectionpath,
outputDir: collectionpath,
One of the collection folders has foldername.11tydata.js
const todaysDate = new Date();
const isDev = require("../_data/isdevelopment")();
function showDraft(data) {
if (isDev) return true;
const isDraft = "draft" in data && data.draft !== false;
const isPostInFuture =
"scheduled" in data ? data.scheduled > todaysDate : false;
return !isDraft && !isPostInFuture;
}
const collectionpath = "/technical-seo/images";
module.exports = () => {
return {
eleventyComputed: {
eleventyExcludeFromCollections: (data) =>
showDraft(data) ? data.eleventyExcludeFromCollections : true,
permalink: (data) => (showDraft(data) ? data.permalink : false),
},
collectionpath
};
};
So, I need to tell image.js to LOOK in the folder and read the 11tydata and establish what the path variable will be to create the image. Haven't figured out cache yet.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading _11ty/image.js alongside the folder’s foldername.11tydata.js to understand how collectionpath is currently defined and consumed. Determine the intended behavior for resolving per-folder data and caching, with completion requiring the image plugin to process each collection’s images using that collection-specific path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100