1. 使用自定义过滤器

  2. 创建过滤器文件:在 Hexo 项目根目录的 scripts 文件夹中创建 add_image_prefix.js 文件。(如果没有 scripts 文件夹,可以新建一个。)

  3. 添加以下代码到add_image_prefix.js文件中

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    hexo.extend.filter.register('before_post_render', function (data) {

        const prefix = 'http://daydream-oss.noahdesu.online/'; //(写你的路径)

        data.content = data.content.replace(/!\[(.*?)\]\((.*?\/img\/.*?)\)/g, function (match, alt, src) {

            return `![${alt}](${prefix}${src})`;

        });

        return data;

    });