hexo

Hexo: How to retrieve post asset folder inside a custom tag


I'm creating a custom tag to insert a more advanced image html code in a post.

I cannot find a way to refer to the post asset folder inside the custom tag.
In markdown we have the snippet {% asset_path image_name %} that retrieve the full path to a post image.
I would have the same inside custom tag js file.

I've not been able to find something useful in the hexo site documentation.

Any help would be appreciated.

EDIT: after further analysis I've realized there is no way to refer post asset folder in a custom tag, other than passing the post asset path as a function parameter.
So the new question would be, is it possible to use the {% asset_path %} tag inside a custom tag snippet, like this {% image_p 'img_name.jpg' 'param2' 'param3' 'asset folder tag' %}?

Pietro


Solution

  • I suggest you make that path configurable and use something like:

    <img src="<%- config.asset_folder_root %><%- item.image_path %>" />
    

    EDIT:

    If you have an asset folder for each post, you can add a custom property to your front matter. So for each post.md, at the beginning you would have something like:

    title: Hello World
    date: 2013/7/13 20:46:25
    asset_folder: /dummy/path/to/folder
    ---
    
    [... your blog post content ...]
    

    And then you can reuse that access that property anywhere in your template by using item.asset_folder:

    <img src="<%- item.asset_folder %><%- item.image_path %>" />