Search code examples
jekyllkramdown

Avoiding repeating long paths in image tags


I'm using Jekll and kramdown to build a static side.

I am often repeating the same large paths to things in assets in image tags, like:

![Some image title](/assets/foo/bar/2019-03-17/more/stuff/groundbreaking-plot.svg)

Can I somehow save the /assets/foo/bar/2019-03-17/more/stuff portion in a per-page variable so I can refer to it succintly in the markdown, like:

![Some image title](??assets_for_this_entry??/groundbreaking-plot.svg)

Solution

  • Yes, you can set it in the front matter. You can set custom variables for each page.

    ---
    ... other stuff in front matter
    myPath: /assets/foo/bar/2019-03-17/more/stuff
    ---
    
    ![]({{ page.myPath }}/image.svg }}}