hakyll icon indicating copy to clipboard operation
hakyll copied to clipboard

Generating multiple resources from one input file, yet in single version

Open konn opened this issue 7 years ago • 3 comments

When I generate HTML page from TeX source, I sometime have to convert TikZ diagrams to external svg orpng files, and replace it with <img> or <object> tags.

Currently, I do this with Hakyll by parsing LaTeX source code tree, extract images to svgs, and place them to the designated directory. For example, if math/great-article.tex includes three diagrams, then my current code do the following thing,

  1. Temporarily create images.tex which includes only diagrams,
  2. Typeset it and use convert to generate image-{1..3}.png, and
  3. mkdir -p math/great-article and copy image-{1..3}.png to math/great-article/.

This procedure works, but not so fine; generated images are recognised and copied to _site only when the next time I run site build. Hence, there is sometimes the case that generated images are not deployed properly to the remote server. The point is that the current versioning functionality don't work here, because the number of generated resources will be dynamically changed.

It seems that there is currently no way to achieve this properly. So I request the functionality to:

  1. Dynamically generate multiple resources from one source in one version, and
  2. register all of them at once.

konn avatar Feb 09 '18 10:02 konn

Any updates? I'm also interested in creating new items on-the-fly, for similar reasons (placing generated SVG into separate image files instead of awkward base64-encoded data URLs)

lierdakil avatar May 12 '19 20:05 lierdakil

@lierdakil @konn Yes -- I think this can actually be done quite elegantly by having a single custom resource -- something along the lines of data PostWithImages = PostWithImages String [(String, ByteString)] and then having a Writable instance that writes out multiple files.

I've put a TODO item to write this out in a bit more detail this week.

jaspervdj avatar May 12 '19 21:05 jaspervdj

@jaspervdj, yep, that works, although generating links to the image files is a bit awkward (essentially duplicated code in link and filepath generation). Thanks for the pointer!

lierdakil avatar May 13 '19 08:05 lierdakil