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

This is really handy, thanks for sharing!

For better asset management: perhaps there’s a way of combining macros with the logseq-localassets-plugin:

plugin demo

How does the Markdown look like when using this plugin?

It looks like ![image name](../file/path.extension), as defined in embedHelper.ts

It works with both files in the assets folder and other local folders. There are, of course, other ways of embedding media in Logseq.

So is the plugin just supposed to prompt the user with the file selection dialog instead of manually typing an absolute path?

Or does the plugin make relative paths work outside the graph folder?

And how do you think it could be combined with macros?

Yes, that’s it.

It doesn’t change the functionality, just makes it less of a pain to type out. It uses absolute paths for other assets, though.

The macros you showed here are great for keeping things concise and short. This is especially useful for, say, a video or photo that is using the HTML or Hiccup method of embedding because the user needs to access additional properties, but the user doesn’t want the markup to be very long.

To give the example of another plugin: The emoji picker plugin is currently facing this issue for custom emojis. A custom emoji looks like this when it’s not being edited:

image

But in edit mode, it looks like this:

Anyway, back to your macro ideas + the local assets plugin…
The issue with just using the macros is that you still have to remember the file name and its location, or browse through your folders, copy the file name, and return to Logseq. The plugin makes finding and selecting the file you’re looking for more efficient.

1 Like

You made the perfect explanation, thank you!

Anyway I heard Logseq 0.9.0 will have a way to “mount” external folders into the graph one, so I will wait and see what the official workflow will be!

1 Like

Interesting! I’m looking forward to exploring that feature as well.