0%

Inserting images into Hexo posts with Typora

Hexo’s built-in asset mechanism is hard to use. This post shows how to painlessly insert images when editing Hexo posts with Typora.

Typora

In Preferences:

image-20200710205313639

File structure:

1
2
3
4
5
6
hexo/
source/
_posts/
some-post.md
some-post/
image.png

In some-post.md:

1
![alt](some-post/image.png)

Hexo

In hexo/_config.yml

1
post_asset_folder: true

In hexo root folder:

1
npm install --save hexo-asset-link

In node_modules/hexo-asset-link/index.js :

1
2
3
4
// strip domain
path_html = path_html.replace(path_html.split("/")[0], "");
// image path in rendered HTML:
// /YYYY/MM/DD/some-post/image.png

This will generate absolute paths for the images in rendered HTML (instead of relative path), which is useful when contents of a post are also displayed from the homepage (which lies in a different folder).