环境

windows

  • 安装nodejs
    • node v20
    • 切换镜像源 npm i -g nrm
    • 切换淘宝镜像源 nrm use taobao
  • 安装 hexo

    • 全局安装 npm i hexo-cli -g
    • 初始化项目 hexo init blog
    • 进入项目 cd blog
    • 安装依赖 npm install
    • 启动项目 hexo server
  • 安装git

    • 下载安装 git
    • 配置git
      • 配置用户名 git config --global user.name "your name"
      • 配置邮箱 git config --global user.email "your email"
    • 进入项目目录 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
  • 部署项目到vercel【完全免费】

    • 使用github登录vercel
    • 选择需要自动部署的项目blogs
      • 等待构建完成即可访问,可自定义域名
    • 可选自定义配置settings
      • Build & Development Settings
        • Framework Preset 选择 hexo
        • Build Command 输入 hexo algolia && hexo generateOverride开启
        • Output Directory 输入 publicOverride开启
        • 点击Save
      • Node.js Version
        • 选择20.x
        • 点击Save
    • 代码提交即可触发自动化构建,提交指令git push origin main
  • 部署到github

    • 配置github仓库
      • 创建cxvh.github.io仓库
    • 项目安装依赖包:npm install hexo-deployer-git
    • 项目根目录下_config.yml文件配置:
      • deploy
        • type 选择 git
        • repo 输入 https://github.com/cxvh/cxvh.github.io.git
        • branch 选择 main
    • 配置"deploy":"hexo deploy"package.json文件的scripts
      • 执行构建: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 cl
hexo clean
# 打包
hexo g
hexo generate
# 发布
hexo d
hexo deploy
# 运行
hexo s
hexo server -p 80

安装皮肤

  • 安装皮肤npm i hexo-theme-butterfly
  • 根目录_config.yml文件配置:theme: butterfly

站点地图/搜索引擎收录

1
2
3
4
5
6
7
8
9
10
11
# 查看是否被收录
site:cxvh.github.io

# 进入:[百度搜索提交入口](https://ziyuan.baidu.com/linksubmit/url?sitename=http%3A%2F%2Fsite%3Acxvh.github.io)
# 验证个人网站 提交 url 地址

# 增加站点地图
npm install hexo-generator-sitemap hexo-generator-baidu-sitemap --save
# 目录下找到 sitemap.xml 以及 baidusitemap.xml 这两个文件已经生成了。
hexo generate
hexo deploy

配置

内容多标签或多分类配置

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 配置


hexo 常见错误整理

端口占用解决方法:关掉占用端口的进程、或者更改端口hexo s -p 4001

文件命名不能使用 HTML 中有用的字符实体(如:03.首页:接口定义&组件拆分.md),否则生成的 sitemap.xmlbaidusitemap.xml 无法正常解析
具体参考 字符实体 HTML ISO-8859-1