Hexo相关

Tricy Zhou Lv3

测试图片

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

CLEAN

1
$ hexo clean

Run server

1
$ hexo server / hexo s

More info: Server

Generate static files

1
$ hexo generate / hexo g

More info: Generating

Deploy to remote sites

1
$ hexo deploy / hexo d

More info: Deployment

官网:https://hexo.io/zh-cn/

彻底解决Hexo图片不显示问题

保证图片在和md同名文件夹,文件x.md,图片./x/y.png

  1. 首先安装hexo-renderer-marked

    1
    npm install hexo-renderer-marked --save
  2. 修改配置_config.yml

    1
    2
    3
    4
    post_asset_folder: true
    marked:
    prependRoot: true
    postAsset: true
  3. md里图片引用

    1
    2
    ![y.png] 注意和md引用写法区别,此时typora打开,图片不显示
    ![./x/y.png] 只有配置成这个样子,md编辑器才能正常渲染,如下:
  4. md中也想显示怎么办?(亲测有效)

    核心原理就是在md渲染html前把路径替换掉

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    // scripts/asset-path-fix.js注意和source同级目录
    'use strict';

    function getPosition(str, m, i) {
    return str.split(m, i).join(m).length;
    }

    hexo.extend.filter.register('before_post_render', function(data) {
    var config = hexo.config;
    if (!config.post_asset_folder) return;

    // 提取 slug
    var link = data.permalink;
    var beginPos = getPosition(link, '/', 3) + 1;
    var endPos = link.lastIndexOf('/') + 1;
    link = link.substring(beginPos, endPos);
    var slug = link.split('/').filter(function(elem) { return elem !== ''; }).pop();

    // 替换 Markdown 中的 ./slug/xxx 为 xxx
    // 例如: ./hello-world/2022020901.jpeg -> 2022020901.jpeg
    var pattern = new RegExp('!\\[([^\\]]*)\\]\\(\\./' + slug + '/([^)]+)\\)', 'g');

    data.content = data.content.replace(pattern, '![$1]($2)');

    return data;
    });

补充

Q: github 403
A: hexo用户和git默认用户不一致,增加新用户并在~/.ssh/config配置,另外在_config.yml中https改为ssh

Q: next主题设置失败
A: 原因是hexo在5.0之后把swig给删除了需要自己手动安装 npm i hexo-renderer-swig

参考:https://zhuanlan.zhihu.com/p/26625249

Q:hexo多机部署主题丢失

参考:使用 master 和 hexo 两个分支

  • Title: Hexo相关
  • Author: Tricy Zhou
  • Created at : 2026-04-26 10:31:00
  • Updated at : 2026-04-26 12:34:59
  • Link: https://redefine.ohevan.com/2026/04/26/hello-world/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments