用hexo+cloudflare搭建博客

下载node.js

在windows上边安装node.js

1.访问https://node.js.org/

2.下载LTS版本

3.运行安装程序,一直点击”next”即可

4.验证安装

1
2
node -v
npm -v

初始化hexo项目

安装完node.js后,在当前目录执行

1
2
3
4
5
6
7
8
#全局安装Hexo CLI
npm install -g hexo-cli

#初始化Hexo项目
hexo init my-blog
cd my-blog
npm install

选择主题

安装butterfly主题

1
npm install hexo-theme-butterfly

配置博客

编辑_config.yml文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 网站信息
title: 你的博客名称
subtitle: '技术分享与学习记录'
description: '专注于前端/后端/全栈技术分享'
keywords: '技术博客,编程,开发'
author: 你的名字
language: zh-CN
timezone: 'Asia/Shanghai'

# URL 配置(自定义域名时需要修改)
url: https://yourdomain.com
root: /

# 主题
theme: butterfly

创建文章

1
2
3
4
5
# 创建新文章
hexo new post "我的第一篇技术文章"

# 本地预览
hexo server

访问http://localhost:4000查看效果

部署到Cloudflare Pages

1.创建github仓库

1
2
3
4
5
6
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/你的用户名/my-blog.git
git push -u origin main

2.在claudflare配置

  • 登录cloudeflare dashboard
  • 进入Pages-Create a project
  • 授权Connect to Git
  • 授权Github并选择你的仓库
  • Framework preset(框架预设):none
    • 配置构建设置:
    • Build command(构建命令):hexo generate
    • Build output directory(构建输出目录):public

3.绑定自定义域名

  • 在Pages项目设置中-Custom domains
  • 添加你的域名