Demo Plots Gallery

Basic stuff

This doesn't require anything specific, just note the use of the macro @OUTPUT which creates a path for the image which you don't have to manage and that makes inputting the image easier.

x = randn(10)
y = randn(10)
figure(figsize=(8, 6))
plot(x, y, ls="none", marker="x", markersize=10)

Inputting the fig is just as simple as \fig{f1.svg} no path needed:

Some notes:

If you don't care that the deployment is slow (runs every cell every time), then this is probably all you need.

Avoiding re-evaluation

This will get better in Franklin but, for now, the kind of stuff you could do to avoid re-evaluating everything when you deploy is:

this quickly becomes a bit tricky as you have to keep track of whether an image needs to be updated or whether an image is orphaned (has been generated but you don't need it anymore). This is doable though. The recommendation would be to have each code block generate a figure with exactly the name of the code block.

x = collect(0:0.1:5)
y = @. x * exp(-sin(x))
figure(figsize=(8, 6))
plot(x, y)

The function lx_exfiga does some of this.

using PyPlot
x = collect(0:0.1:5)
y = @. cos(x) * exp(-sin(x))
figure(figsize=(8, 6))
plot(x, y, lw=2)

That function could be extended in the following way:

I'm not doing this here as I'm not 100% sure you want to go down this road, you might be fine with evaluation at every deployment.

Generating a list of all plots

As far as I understand, you'd like to be able to have a list of plots and generate a gallery of thumbnails on which users can click and then they'd see a specific page or code or whatever.

I think potentially the easiest path here would be to leverage the name of things and call figures with something that looks like the path. So if you do joinpath(@OUTPUT, "fig.svg") on index.md, that figure will be saved at

_site/assets/index/code/output/fig.svg

it then becomes relatively easy to just scrape all this by just exploiting the generated file names.

One thing though is that you want the evaluation of such a function to happen last, i.e. after all pages have been (re)processed. For this you just need to put a @delay in the definition of the hfun:

you might want to add some further filtering to this etc but I'm hoping this shows some of the stuff you could do.