安装 hexo 并生成网页

安装 hexo

创建一个任意名字的文件夹,这里我创建的是 My_Blog 。 进入该文件夹,右键进入 Git Bash 输入:

npm install -g hexo-cli


输入:

hexo init

初始化我们的博客。

输入:

hexo g

生成静态文件。

输入:

hexo s

进行本地查看。

在浏览器中输入: http://localhost:4000/

可以看到我们的博客已经布置成功了。

部署到github上

在 My_Blog 文件夹中,用笔记本打开 _config.yml 文件,在最后添加:

deploy:
type: git
repository: https://github.com/你的 github 用户名/你的 github 用户名.github.io.git #你的仓库地址
branch: main

在 My_Blog 文件夹中,打开 Git Bash,输入:

npm install hexo-deployer-git --save

安装 Git 部署插件。

第一次提交到 github ,会报错,我们需要先配置邮箱和用户名。

git config --global user.email "you@example.com" #注册 github 时的邮箱

git config --global user.name "Your Name" #注册 github 时的用户名

依次输入:

hexo clean #清除缓存文件和静态文件

hexo g #生成静态文件

hexo d # 部署到对应的 github 仓库

在浏览器中输入:

https://你的 github 用户名.github.io/

就可以看到相应的网站:

同时对应的 github 仓库也存在文件。