hexo博客图片问题

markdown文章图片路径和hexo博客发布时图片路径不同

1. post_asset_folder

hexo/_config.yml 中找到 post_asset_folder设置为true

表示在建立文件时,hexo自动建立一个与文章同名的文件夹

2. 安装hexo-asset-image

1
$ npm install hexo-asset-image --save

3. 使用

1
$ hexo new test

hexo/source/_post 下对应test.md同级有文件夹test,图片放在文件夹下

1
2
3
test
|———— 1.jpg
test.md

在test.md中使用图片,使用Typora软件

在头上设置 typora-root-url: ./test 页面内使用![](/1.jpg) 如图

4. 2021更新 在nextT 8.8.0中生成图片路径报错

网页中的图片路径变为这样?

update link as:-->/.io//1.jpg

找到 hexo-asset-image文件中的js文件

hexo/node_modules/hexo-asset-image/index.js

修改link字符串的分割方式,大概从17行开始

var link = data.permalink;可以得到当前页的完整路径 https://wtlumos.github.io/zh-CN/2021/10/14/test/

直接从第三个’/‘开始切

而关于页面的生成是 https://wtlumos.github.io/about/index.html 故把‘index.html’字符串切掉,这个是作者已经实现的

1
2
3
4
5
6
7
8
9
10
11
12
if(/.*\/index\.html$/.test(link)) {
// when permalink is end with index.html, for example 2019/02/20/xxtitle/index.html
// image in xxtitle/ will go to xxtitle/index/
appendLink = 'index/';
//var endPos = link.lastIndexOf('/');
link = link.substring(beginPos,link.lastIndexOf('/'))+"/"+appendLink;
}
else {
//var endPos = link.lastIndexOf('.');
link = link.substring(beginPos);
}
//link = link.substring(beginPos,link.lastIndexOf('/'))+"/"+appendLink;
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2018/07/02/hexo博客图片问题/
  • 发布时间: 2018-07-02 11:44
  • 更新时间: 2023-04-15 16:17
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!