Diagrams In Hakyll!
I stumbled across this blogpost of Corentin
Dupont
where he put together a library that allows you to modify your hakyll blog so
that you can have inline diagrams! As anyone knows, this was amazingly
exciting to me, because I love
diagrams
.
So I quickly tried to set it up; but, much to my sadness it didn’t immediately work.
Luckily, however, I was able to make it worked by hacking around in the two relevant repos:
The main result is a function, pandocCompilerDiagrams
, that I included into
my hakyll site file like so:
match "posts/*" $ do
route $ setExtension "html"
compile $
(pandocCompilerDiagrams "images/diagrams" <|> pandocMathCompiler)
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
And so now, I can have inline diagrams! Check it out:
Imagine we had a circle:
= circle 1 example
But now, what if the circle was repeated 5 times
= hcat (take 5 $ repeat (circle 1)) example
Cool!
To celebrate, let’s draw the Sierpinksi triangle:
The basic building block:
= d === (d ||| d) # centerXY
sierp d = sierp (triangle 1) example
Let’s go!
= d === (d ||| d) # centerXY
sierp d = foldl (\d _ -> sierp d) (triangle 1) [1..3] example
Colours!
import Data.Colour.Palette.ColorSet
= rybColor (n*2)
color n
= d1 === (d2 ||| d2) # centerX
sierp d n where
= d # bg (color n)
d1 = d # bg (color (n+1))
d2
= foldl step d0 [0..5]
example where
= triangle 1 # lw 0
d0 = sierp d (n*2) step d n
Happy days!