版本:Hexo5.0.2(Hexo3以上即可)

解决方案如下:

  • 修改配置文件

  • 在根目录下配置文件_config.yml 中有 post_asset_folder:false改为true。

  • 这样在建立文件时,Hexo会自动建立一个与文章同名的文件夹,这样就可以把与该文章相关的所有资源(图片)都放到那个文件夹里方便后面引用

  • 我这里放的图片是:sky2.jpg

  • 安装插件:hexo-asset-image(插件经测试无问题)

    1
    npm install https://github.com/7ym0n/hexo-asset-image --save(使用cnpm速度相当会快点,当然npm也可以滴)
  • 使用这个插件来引入图片,而不是网上那些方法里说的用传统md语法相对路径的方法。

  • 插入图片时用这种方式:

    1
    {% asset_img sky2.jpg This is an test image %}
  • 其中sky2.jpg就是你要引用的图片,我这里就是sky2.jpg,后面的This is an test image是图片描述,可以自己修改。

具体示例:

1
2
3
4
5
6
7
8
9
10
11
---
title: A sunny day
date: 2020-08-14 11:24:30
tags:
- weather
categories:
- daily
---
晴れた日より?菜が必要です。
{% asset_img sky2.jpg This is an test image %}
{% asset_img sky3.jpg This is an test image %}
  • 这样就能成功显示了,测试下吧:
    1
    hexo cl && hexo g && hexo d

Alex博客