hexo建站总结

前言

最近突然想整理下技术的思路,刚好看到码云也有Gitee Pages 服务,支持Jekyll、Hugo、Hexo。试验了下决定选用hexo搭建博客。

软件准备

以下均为在windows环境下操作,首先先安装以下程序

git设置

$ git config --global user.name "fjcqv"
$ git config --global user.email fjcqv@qq.com

有必要可设置git使用ssh秘钥,这样可以免登录。

npm设置

//设置npm库位置
npm config set prefix "D:/Program Files/nodejs/npm_global"
npm config set cache "D:/Program Files/nodejs/npm_cache" 

//在中国,中国,中国,你应该设置淘宝镜像来加速下载。
npm config set registry "https://registry.npm.taobao.org/"
npm config set electron_mirror "https://npm.taobao.org/mirrors/electron/"

使用npm安装Hexo

npm install hexo-cli -g
hexo init blog
cd blog
npm install
hexo server

然后访问localhost:4000就能看到雏形。

选择hexo主题

  1. 这边我们使用nexT作为主题。 先从https://github.com/theme-next/hexo-theme-next fork到自己仓库。 然后在站点根目录终端输入
//创建子模块
git submodule add "git@github.com:fjcqv/hexo-theme-next.git" "themes/next"

//或者以下命令,个人觉得上面的好处是修改主题维护方便点。
git clone https://github.com/theme-next/hexo-theme-next themes/next
  1. 打开站点配置文件_config.yml, 找到 theme 字段,并将其值更改为 next。
# 扩展
## 插件: https://hexo.io/plugins/
## 主题: https://hexo.io/themes/
theme: next
  1. 重新生成
hexo clean  //清除缓存
hexo g  //重新生成代码
hexo s  //部署到本地

//然后打开浏览器访问 localhost:4000 查看效果

部署

选择部署仓库

  1. 本文选择码云,毕竟在国内,访问速度快点
  2. 建立一个与自己个性地址同名的项目

配置

打开站点配置文件_config.yml, 找到 deploy 字段修改。

# 部署
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: git@gitee.com:cqv/cqv.git
  branch: master
  message: '站点更新:{{now("YYYY-MM-DD HH:mm:ss")}}'

安装插件并部署

npm install hexo-deployer-git --save
hexo d  

开启pages服务

码云需要在项目选择gitee pages服务将其开启,才能访问。