关于abbrlink和asset-image不兼容问题

hexo-abbrlink:给每篇文章生成十六进制的非中文路径

hexo-asset-image:给图片添加一个绝对路径

hexo-abbrlinkhexo-asset-image一起用的时候,无论怎么修改生成路径,要么封面加载不出来,要么文章内图片加载不出来,所以需要修改下面的文件,才能解决。

Your Blog Root\node_modules\hexo-asset-image\index.js

  1. 在12行var link = data.permalink; 的下一行添加 var abbrlink = data.abbrlink

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    hexo.extend.filter.register('after_post_render', function(data){
    var config = hexo.config;
    if(config.post_asset_folder){
    var link = data.permalink;
    //
    var abbrlink = data.abbrlink // 添加:适配abbrlink
    //
    var beginPos = getPosition(link, '/', 3) + 1;
    var appendLink = '';
    // In hexo 3.1.1, the permalink of "about" page is like ".../about/index.html".
    // if not with index.html endpos = link.lastIndexOf('.') + 1 support hexo-abbrlink
  2. 在60行附近$(this).attr('src', config.root + link + src);的这一行修改为 $(this).attr('src', config.root + 'posts/' + abbrlink + '/' + src); //适配abbrlink

    1
    2
    3
    //$(this).attr('src', config.root + link + src);
    $(this).attr('src', config.root + 'posts/' + abbrlink + '/' + src); //适配abbrlink
    //
  3. 三连即可

参考链接:

非常感谢作者,但是当有图片存在时,有bug · Issue #19 · rozbo/hexo-abbrlink (github.com)

使用hexo-abbrlink及解决与hexo-asset-image不适配的问题_hexo-assert-image导致js文件被替换-CSDN博客