Hexo博客搭建系列

准备工作

1. 域名:

  可以使用.xyz域名或者免费的dodbs.org或者de5.net域名DigitalPlat

2. 账号:

  Github
  Cloudflare

3. 软件

  Node
  Git
  Notepad++(Win系统)
  CotEditor(Mac系统)

4. 配置Github

1
2
3
git config -l  //查看所有配置
git config --system --list //查看系统配置
git config --global --list //查看用户(全局)配置
1
2
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱"

5. 生成密钥

npm update –save hexo-theme-fluid
ssh-keygen -t rsa -C “你的邮箱”

1
2
- 将ssh公钥配置到Github
- 测试配置效果

ssh -T git@github.com

1
2
3
4
5
#### 6. 创建Github.io仓库
必须使用**<用户名>.github.io**的仓库

### Hexo搭建

安装Hexo

npm install -g hexo-cli && hexo -v

验证是否成功

hexo -v

#初始化 Hexo 项目安装相关依赖
hexo init blog-demo
cd blog-demo
npm i

启动项目

hexo cl && hexo s

1
2
3

### Hexo挂载到Github Pages
#### 1. 安装依赖

安装 hexo-deployer-git

npm install hexo-deployer-git –save

1
2
#### 2. 修改配置文件
_config.yml最后一行修改为github的地址,比如

deploy:
type: git
repository: git@github.com:your_github_name/your_github_name.github.io.git
branch: main

1
#### 3. Hexo部署到Github

hexo clean && hexo generate && hexo deploy
1
2
3
4
5
6
7
8
  ### Hexo博客挂载到Cloudflare Pages
Workers 和 Pages -> Pages -> 连接到 Git -> 部署

### 博客主题安装
推荐使用 [anzhiyu](https://github.com/anzhiyu-c/hexo-theme-anzhiyu) 和 [Fluid](https://github.com/fluid-dev/hexo-theme-fluid)

#### [anzhiyu](https://github.com/anzhiyu-c/hexo-theme-anzhiyu)

下载

git clone -b main https://github.com/anzhiyu-c/hexo-theme-anzhiyu.git themes/anzhiyu

第一次使用需要安装 pug 以及 stylus 的渲染器

npm install hexo-renderer-pug hexo-renderer-stylus –save

修改 hexo 配置文件_config.yml,把主题改为anzhiyu

应用主题

//本地预览
hexo cl; hexo s

//推送更新上线
hexo cl; hexo g; hexo d

1
2
3
4

### 配置模板

#### post.md:新建博文模板

title: Hexo博客搭建系列 #【必需】页面标题
date: 1770864504366 #【必需】页面创建日期
updated: #【可选】页面更新日期
tags: #【可选】文章标签
categories: #【可选】文章分类
keywords: #【可选】文章关键字
description: #【可选】文章描述
top: # 1 置顶
top_img: #【可选】文章顶部图片
comments: #【可选】显示文章评论模块(默认 true)
cover: https://img.090227.xyz/file/ae62475a131f3734a201c.png #【可选】文章缩略图(如果没有设置 top_img,文章页顶部将显示缩略图,可设为 false/图片地址/留空)
toc: #【可选】显示文章 TOC(默认为设置中 toc 的 enable 配置)
toc_number: #【可选】显示 toc_number(默认为设置中 toc 的 number 配置)
toc_style_simple: #【可选】显示 toc 简洁模式
copyright: #【可选】显示文章版权模块(默认为设置中 post_copyright 的 enable 配置)
copyright_author: #【可选】文章版权模块的文章作者
copyright_author_href: #【可选】文章版权模块的文章作者链接
copyright_url: #【可选】文章版权模块的文章作者链接
copyright_info: #【可选】文章版权模块的版权声明文字
mathjax: #【可选】显示 mathjax(当设置 mathjax 的 per_page: false 时,才需要配置,默认 false)
katex: #【可选】显示 katex(当设置 katex 的 per_page: false 时,才需要配置,默认 false)
aplayer: #【可选】在需要的页面加载 aplayer 的 js 和 css,请参考文章下面的音乐 配置
highlight_shrink: #【可选】配置代码框是否展开(true/false)(默认为设置中 highlight_shrink 的配置)
aside: #【可选】显示侧边栏 (默认 true)
swiper_index: 10 #【可选】首页轮播图配置 index 索引,数字越小越靠前
top_group_index: 10 #【可选】首页右侧卡片组配置, 数字越小越靠前
ai: #【可选】文章ai摘要
background: “#fff” #【可选】文章主色,必须是16进制颜色且有6位,不可缩减,例如#ffffff 不可写成#fff

[up主专用,视频内嵌代码贴在这]