0%

hexo解决图片问题

现在我也没有找到完美的解决方案。

平时是使用typora来写marakdown文档,但是mac的typora保存图片时候,设置在同目录下生成图片文件夹会有.assets后缀。例如test.md的图片文件夹为test.assets

下面给出临时的解决方案

1. 修改hexo的_config.yml配置文件

1
2
3
4
post_asset_folder: true
marked:
prependRoot: true
postAsset: true

2. 安装插件

1
2
sudo npm install hexo-asset-image --save
sudo npm install hexo-renderer-marked --save

3. 修改hexo-asset-image配置文件

blog/node_modules/hexo-asset-image/index.js 进行修改

1
2
3
4
// $(this).attr('src', config.root + link + src);
// console.info&&console.info("update link as:-->"+config.root + link + src);
$(this).attr('src', src);
console.info&&console.info("update link as:-->"+src);

4.文章撰写与发布

使用typora正常写文档test.md,这时图片文件夹为test.assets,复制该图片文件夹一份将其命名为test,然后执行hexo clean && hexo g && hexo s

5.补充

其实问题的关键在于hexo在生成时候,只会把和test.md同名的文件夹test下的图片复制到html页面中,如果图片在test.assets目录下,hexo不会复制图片。生成的html文件按照日期排序在/blog/public/2024/02/01/test/index.html 目录下。

image-20240202155120911

参考

Typora+Hexo图片上传路径问题
Hexo + Typora + 开发Hexo插件 解决图片路径不一致