kubenstein / middleman-simple-thumbnailer

Middleman extension that allows you to create image thumbnails by providing resize_to option to image_tag helper
MIT License
29 stars 17 forks source link

New architecture #13

Closed ymph closed 7 years ago

ymph commented 8 years ago

This issue has been opened to gather the discussions about a new architecture for the extension.

When analysing the middleman extension workflow when writing code for the PR #12, it has appeared that middleman-simple-thumbnailer doesn't follow the expected extension workflow.

Middleman expects that extensions know the list of files they generate/manipulate before the build phase. In fact, Middleman expects that extensions update the sitemap in the "manipulate_resource_list" callback. This callback is called before the build, and the list of resource can not be modified afterwards.

But in its current implementation, middleman-simple-thumbnailer knows the list of file to generate after the build phase, since they are compiled when the template helper is called.

The issue #10 is an example of why this is a problem. The asset_hash extension works on the sitemap to create the files hashes. Therefore it will not work on files that are not "declared" in the sitemap, such as those created by middleman-simple-thumbnailer.

My suggestion for a correction is to introduce a data file listing the resized images. This file could be written in advance by the user, or/and more conveniently updated/created in the image helper. middleman-simple-thumbnailer would now manipulate the site map and generate the files before the middleman build phase. On each image resize the image helper would do the following action:

The main drawback of my suggestion, is that the user have to launch the build twice (and remember to do it) if the list of resized images is modified.

ym

ymph commented 7 years ago

This issue has been solved in version v1.3.0 by introducing the "declarative mode".