本地搭建Hexo

1,下载安装Node.js

2,配置npm镜像

1
npm config set registry https://registry.npmmirror.com/

3,安装hexo

1
2
3
4
5
-- 安装hexo-cli
npm install -g hexo-cli

--初始化hexo 博客
hexo init my-blog

:::warning
① 如果执行初始化报错 :‘hexo’ 不是内部或外部命令,也不是可运行的程序 或批处理文件。可能是未配置path环境变量。执行一下操作:

:::

1
2
3
4
5
6
7
8
9
10
11
步骤 1:确认是否已成功安装 hexo-cli 
npm list -g --depth=0
查看输出中是否有:
├── hexo-cli@...

步骤 2:检查 npm 全局安装路径是否加入系统环境变量 PATH
npm config get prefix
输出可能是:
C:\Users\你的用户名\AppData\Roaming\npm
C:\Program Files\nodejs
确保这个路径已经添加到系统的 PATH 环境变量中。(系统变量和用户变量一并添加)

:::warning
②vscode终端执行不了

重启右键以管理员的身份运行VsCode

:::

4,初始化项目

1
2
3
4
5
6
cd my-blog
npm install

--本地预览博客搭建完成的效果是什么
hexo generate
hexo server

5,博客的全局配置文件配置

1

至此,本地搭建Hexo博客已完成

github托管hexo项目

1,github新建仓库

2,本地项目初始化

1
2
3
4
5
6
7
8
9
git init
git add .
git commit -m "Initial commit"

git branch -M main

git remote add origin git@github.com:Mchood0/mchood0.github.io.git

git push -u origin main

:::warning
本地仓库与github创建密钥ssh

:::

3,修改_config.yml 配置文件,填服务器部署配置

,4,执行命令发布部署到github

1
2
3
4
5
6
--安装了 hexo-deployer-git 插件,不然执行不了hexo deploy命令
npm install hexo-deployer-git --save

hexo clean ; hexo generate; hexo deploy
--检查是否部署成功
hexo d