环境与工具

  • 操作系统:Windows 10/11
  • Node
  • Git
  • Hexo

安装 node

  1. 为防止不兼容问题,选择较低版本如(12.19.0),nodejs 下载

  2. 安装完成后,执行 node -v 命令,看到版本信息,则说明安装成功。

  3. npm 下载各种模块,默认是从国处服务器下载,速度较慢。修改 npm 源,运行如下命令:

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

安装 git

  1. 安装 git

  2. 配置用户名和邮箱:

    git config --global user.name "你的用户名"
    git config --global user.email "你的邮箱"

安装 hexo

  1. 安装 hexo:
    npm install -g hexo-cli
  2. 验证安装:输入 hexo -v 验证是否安装成功。

创建 github repository

  • 创建一个 <用户名>.github.io 的仓库( github 提供的免费 Pages 服务,只对特定 repository 有效)

计算机连接 Github

  1. 执行以下命令生成 ssh 公钥

    ssh-keygen -t rsa -C "你的邮箱"
  2. 用记事本打开开 C:\user.shh\id_rsa.pub,复制内容至 github 上 new ssh key

  3. 测试连接,输入 ssh -T git@github.com

初始并部署 Hexo

本地部署

  1. 初始化
    mrdir blog 
    cd blog
    hexo init
  2. hexo s 启动项目,本地部署

部署到 github pages

  1. 安装 hexo-deployer-git: npm install hexo-deployer-git --save

  2. 修改 _config.yml 文件,将 repository 修改为 github 项目地址即可

    deploy:
    type: git
    repository: git@github.com:Fomalhaut-Blog/Fomalhaut-Blog.github.io.git
    branch: main
  3. 部署到 github 上:hexo clean; hexo generate; hexo deploy 出现Deploy done,则说明部署成功了

部署到 static web

  1. 使用 github 注册 render 账号

  2. Add New Project 创建新的项目,从 github 导入

  3. 自定义名称,然后 deploy