在 github 上自己搭建一个博客

31 阅读1分钟

前置准备

node 环境、github 账号、VPN

开始

  1. 安装 hexo-cli
npm install -g hexo-cli
  1. 生成 blog
hexo init blog
cd blog
npm install
  1. 部署 3.1 申请一个新的 git 仓库:https://github.com/wuhongxing/wuhongxing.github.io

3.2 重写 _config.yml 中的 deploy 配置

deploy:
  type: git
  repo: https://github.com/wuhongxing/wuhongxing.github.io.git
  branch: main
  message: 初次提交

3.3 安装插件

npm install hexo-deployer-git --save

3.4 执行 yarn clean & yarn deploy 即可 然后就可以打开 wuhongxing.github.io 就可以看见我们的博客了。

开始写作

  1. 执行 yarn server,启动一个本地服务,打开页面后,保存更改的内容就能实时看到

  2. 创建新的文章或者页面,可以使用下面的命令,也可以手动

hexo new [layout] <title>
# ex
hexo new post 'test'

主题、插件

  1. 可以到 https://hexo.io/themes/ 上面挑一个自己喜欢的

  2. 安装主题

2.1 git clonetheme 文件夹中

2.2 安装依赖

npm install hexo-wordcount --save
npm install hexo-generator-json-content --save
npm install hexo-generator-feed --save
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save

2.3 在 theme/pure/_config.yml 中开启

busuanzi:
    enable: true  # 不蒜子统计

postCount:
  enable: true  # 是否开启文章字数统计
  wordcount: true  # 文章字数统计
  min2read: true
  1. blog/_config.yml 中的 theme 字段改为你刚才的主题名称

  2. 最后执行 yarn server 就可以看到效果了

参考

  1. 零花费白嫖:免费利用Hexo和GitHub打造个人博客
  2. 官方文档
  3. pure