hexo入门学习: hexo文章中插入图片(二)

在hexo文章中插入图片有两种方式:

  • 使用本地路径:将图片上传到本地
  • 将图片托管到七牛云: 取图片链接在博客里引入

下面介绍第一种方式

hexo文章中插入图片

一. 修改配置文件

打开主页配置文件_config.yml,把post_asset_folder:设置为:true

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: true
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: false
tab_replace:

二. 安装图片上传插件

在你的hexo根目录下,右键点击Git Bash Here,输入npm install hexo-asset-image --save

hexo文章中插入图片

三. 新建博客

执行hexo new "博客文章名称",来生成博文时会在/source/_posts文件夹内除了博客文章名称.md文件外还有一个同名的文件夹(这个文件夹就是用来存储你要在博客插入的图片)。

hexo文章中插入图片

四. 使用

把你的图片放在上一步自动生成的文件夹内,打开你的博客.md文件,输入:

1
![图片加载失败时的替换文字](图片名+后缀) 列如: ![hello](1.jpg)
Fork me on GitHub