一、 搭建环境

网上关于HEXO搭建博客的教程很多,这里推荐桃大大的,每一步写的很详细,原文地址:https://tomhutao.icu/2023/05/10/first/

二、常见问题汇总

1.修改主题后若出现如下代码:“includes/layout.pug block content #recent-posts.recent-posts include includes/recent-posts.pug include includes/pagination.pug ”,或者是“doctype html(lang=config.language) include ./partial/header-base.pug body include ./partial/header.pug main section.main-content !{ body } include ./partial/footer.pug script(src=url_for(‘scripts/dark.js’)) if is_post() script(src=url_for(‘scripts/post.js’))”,那是因为没有渲染器,输入此代码安装pug和stylus渲染器“npm install hexo-renderer-pug hexo-renderer-stylus”,然后 hexo clean ,hexo g。

2.hexo部署报错hexo d报错Spawn failed:在.deploy_git/.git文件夹下打开config配置文件,在[core]中添加上下面两句话:
autocrlf = false
safecrlf = false,
在最后边加上三行(其实其他地方也存在.git文件,如果不确定就把全部.git后面都加上下面三行):
[user]
email=your email
name=your name
关闭VPN或其它智慧上网软件。
3.配置hexo到github时config.yml文件,最后一行的branch一定要改成main。

三、 撰写博客

全部部署完成后,开始撰写博客,在source的posts目录下右键Git bash here,输入命令 hexo n “文章标题”,会在
posts目录下生成以”文章标题“命名的md文件,使用VSCode或者其他md编辑器开始编辑。
编辑完成后,hexo c 清除旧数据,hexo g生成静态文件,hexo d部署到github。 Git命令全程均在posts目录下运行。