站长自己的hexo博客:点击浏览
安装 hexo 前提
安装 Hexo 相当简单,只需要先安装下列应用程序即可:
- 安装 Git
- 安装 Node.js (Node.js 版本需不低于 10.13,建议使用 Node.js 12.0 及以上版本)
- 安装 Hexo
- GitHub 创建个人仓库
- 生成 SSH 添加到 GitHub
- 将 hexo 部署到 GitHub
- 设置个人域名
- 发布文章
安装 Hexo
所有必备的应用程序安装完成后,即可使用 npm 安装 Hexo。
$ npm install -g hexo-cli
Hexo 安装完后依旧用 hexo -v 查看一下版本
接下来初始化一下 hexo
在 D 盘创建一个文件名为我的博客(文件名可自行命名)
然后输入 cd 我的博客
在输入以下命令
hexo init myblog
初始化完成
myblog 目录出现以下文件
node_modules: 依赖包 public:存放生成的页面 scaffolds:生成文章的一些模板 source:用来存放你的文章 themes:主题 ** _config.yml: 博客的配置文件**
然后输入依赖
npm install
然后输入
hexo g hexo server
打开 hexo 的服务,在浏览器输入 localhost:4000 就可以看到你生成的博客了。
GitHub 创建个人仓库
首先,你先要有一个 GitHub 账户,去注册一个吧。
注册完登录后,在 GitHub.com 中看到一个 New repository,新建仓库
创建一个和你用户名相同的仓库,后面加.github.io,只有这样,将来要部署到 GitHub page 的时候,才会被识别,也就是 xxxx.github.io,其中 xxx 就是你注册 GitHub 的用户名。我这里是已经建过了。
将 hexo 部署到 GitHub
这一步,我们就可以将 hexo 和 GitHub 关联起来,也就是将 hexo 生成的文章部署到 GitHub 上,打开站点配置文件 _config.yml,翻到最后,修改为 liubaozi 就是你的 GitHub 账户 deploy: type: git repo: https://github.com/liubaozi/liubaozi.github.io.git branch: main
这个时候需要先安装 deploy-git ,也就是部署的命令,这样你才能用命令部署到 GitHub。
npm install hexo-deployer-git --save
如果输入 hexo d 出现以下错误
fatal: unable to auto-detect email address (got z@DESKTOP-DPE3A08.(none)) error: src refspec HEAD does not match any error: failed to push some refs to https://github.com/xxxx/xxxx.ithub.io.git 可以先键入:
git config --global user.email 你的邮箱 git config --global user.name 你的gihub名字 例如: git config --global user.email 123456@163.com git config --global user.name xxxxx
然后
hexo clean hexo generate hexo deploy
评论