环境准备

1. 安装 Node.js

  • 下载 Node.js v20
  • 切换 npm 镜像源(推荐淘宝源):
    1
    2
    npm i -g nrm
    nrm use taobao

2. 安装 Hexo

  • 全局安装 Hexo CLI:
    1
    npm i hexo-cli -g
  • 初始化项目并安装依赖:
    1
    2
    3
    hexo init blog
    cd blog
    npm install
  • 启动本地服务:
    1
    hexo server

3. 安装 Git 并配置

  • 下载 Git
  • 配置用户名和邮箱:
    1
    2
    git config --global user.name "your name"
    git config --global user.email "your email"
  • 初始化仓库并推送到 GitHub:
    1
    2
    3
    4
    5
    6
    cd blogs
    git init
    git remote add origin https://github.com/cxvh/blog.git
    git add .
    git commit -m "first commit"
    git push -u origin main

自动化部署

1. 部署到 Vercel(推荐,完全免费)

  • 使用 GitHub 登录 Vercel
  • 新建项目,选择要部署的仓库
  • 等待构建完成即可访问,可自定义域名
  • 可选自定义配置(Settings):
    • Build & Development Settings
      • Framework Preset: hexo
      • Build Command: hexo algolia && hexo generate(Override 开启)
      • Output Directory: public(Override 开启)
    • Node.js Version: 选择 20.x
  • 代码提交后自动触发构建:
    1
    git push origin main

2. 部署到 GitHub Pages

  • 创建 cxvh.github.io 仓库
  • 安装部署插件:
    1
    npm install hexo-deployer-git --save
  • 修改项目根目录下 _config.yml
    1
    2
    3
    4
    deploy:
    type: git
    repo: https://github.com/cxvh/cxvh.github.io.git
    branch: main
  • package.jsonscripts 添加:
    1
    "deploy": "hexo deploy"
  • 构建并部署:
    1
    2
    hexo generate
    hexo deploy
  • 访问:https://cxvh.github.io

Hexo 常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 创建文章
hexo n '我的第一篇博客文章'
hexo new '我的第一篇博客文章'

# 创建页面
hexo new page tags # 标签页
hexo new page categories # 分类页
hexo new page archives # 归档页

# 清理缓存
hexo clean

# 生成静态文件
hexo generate

# 部署
hexo deploy

# 启动本地服务
hexo server -p 80

主题与插件

安装主题

  • 安装 Butterfly 主题:
    1
    npm i hexo-theme-butterfly
  • 修改 _config.yml
    1
    theme: butterfly

站点地图与搜索引擎收录

  • 安装插件:
    1
    npm install hexo-generator-sitemap hexo-generator-baidu-sitemap --save
  • 生成地图并部署:
    1
    2
    hexo generate
    hexo deploy
  • 生成的 sitemap.xmlbaidusitemap.xml 位于 public 目录
  • 提交收录入口:百度搜索提交入口

配置建议

多标签/多分类

1
2
3
4
5
tags: [a, b, c]
categories:
- a
- b
- c

基本信息(建议完整填写)

1
2
3
4
5
6
7
title: your title
subtitle: your subtitle
description: your description
keywords: your keywords
author: your name
email: your email
url: your site url

Feed 配置


文件命名规范

  • 文件名避免使用 HTML 字符实体(如:&<> 等),否则 sitemap.xmlbaidusitemap.xml 可能无法解析
  • 参考:字符实体 HTML ISO-8859-1