Macros to improve assets management

Simplify syntax

The following macro:

"png" "![](../assets/$1.png)"

It will let you to just type:

{{png example}}

but when the block is not in edit mode Logseq will just render it like you wrote:

![](../assets/example.png)

this macro makes much sense if you use a lot of PNG images and you want to get rid of the .png too; you can define other macros for other formats.


Same with assets in different folders

In case you place assets in folders other than /assets you can mention them in the macros:

"course" "![](../courses/$1.mp4)"
"drawing" "![](../images/drawings/$1.jpg)"

and eventually if you decide to edit the folder structure of your assets you just need to edit the macros definitions and not to edit all your Markdown files.


Refer assets to current page

Let’s say you have many pages with (numbered) images and you want to keep them organized in folders.
If for example you create for each page a folder like this (including [[]]):

graph/assets/[[Page Name]]

then you can use a macro like this one:

"current" "![](../assets/<%current page%>/$1)"

so that something like this:

{{current 01.png}}

will render different images according to the page it is placed in.

That’s awesome. I don’t really do much to manage my assets; this will make it easier

1 Like