Having your own blog is an excellent way to share knowledge, showcase yourself, or develop a side business. Compared to traditional blogging platforms, static blogs are not only lightweight and secure but also allow complete control over how content is presented.

By combining Hexo and Cloudflare, you can easily set up a free and high-performance personal blog without worrying about server maintenance. This article will detail how to quickly create a blog that offers both speed and security using these two powerful tools.

Preparation Steps

Before you begin, make sure you meet the following requirements:

Install Node.js and Git using the installer packages; I won’t go into further detail here.

Install Hexo

1
2
npm install -g hexo-cli
hexo
Hexo Installation successful
Hexo Installation successful

Create a Hexo Project

After confirming that Node.js, Git, and Hexo are installed, create a project using Hexo.

1
2
3
hexo init my-blog
cd ./my-blog
hexo s
Successfully run
Successfully run

After running, you can preview the site locally by entering http://localhost:4000/ in the address bar.

Web Preview
Web Preview

Customize Hexo Configuration

The default configuration file generated by Hexo is located at my-blog/_config.yml. You can modify parameters such as the blog title and author information as needed. To ensure your site meets SEO standards, the following points are particularly important:

  • title: Blog Title
  • description: A brief description that attracts users to click
  • keywords: Relevant keywords to enhance search engine visibility
  • url: Your blog URL

In the _config.yml file, you can set it up like this:

1
2
3
4
5
6
7
8
title: my blog
description: This is a blog about programming and technology sharing.
keywords: Programming, Technical Blog, Hexo, Static Website
author: author's name
language: zh-CN
timezone: Asia/Shanghai

url: https://domain.com

You can refer to the official documentation for other settings, themes, and plugins. Installing themes and plugins can make your blog both beautiful and functional.

Deploying Hexo Online

Free deployment options include:

  • Uploading to GitHub and deploying with GitHub Pages
  • Uploading to Cloudflare Pages for deployment

Websites deployed with GitHub Pages may have unstable connections in China, while using Cloudflare for acceleration requires a domain name.

Therefore, this article will focus on deploying with Cloudflare Pages for convenience and stability. This blog is deployed using this method.

In the project, build the static resource files in the public directory for use.

1
hexo g

Direct Upload and Deployment on Cloudflare

Open the Cloudflare Dashboard and navigate to the Workers and Pages page.

Cloudflare Pages page
Cloudflare Pages page
Cloudflare Pages upload page
Cloudflare Pages upload page

After creating a name for the project, click Create Project. Then, drag and drop the entire public folder to upload it, and click Deploy Project.

Cloudflare Pages upload resources
Cloudflare Pages upload resources
Cloudflare Pages successfully deploy
Cloudflare Pages successfully deploy

Once the deployment is successful, you can directly access your project using the provided link.

Deploying Projects Using Cloudflare CLI

C3 (create-Cloudflare-cli) is a command-line tool designed to help you quickly set up Workers and Pages applications and deploy them to Cloudflare.

Here are two methods to deploy your project to Cloudflare Pages using the CLI:

Use the command to quickly create a Cloudflare CLI project

Cloudflare Pages CLI project creation
Cloudflare Pages CLI project creation

Place the Hexo static files in the public directory of the CLI project and run the command to deploy to Cloudflare.

Cloudflare Pages CLI project upload
Cloudflare Pages CLI project upload

After a successful upload, you can use the link in the console to access the deployed webpage.

Add CLI to an Existing Project

Add the development dependency wrangler to the project.

Create a wrangler.toml configuration file in the project’s root directory.

wrangler.toml
1
2
3
4
5
6
7
8
9
10
#:schema node_modules/wrangler/config-schema.json
name = "page-name"
compatibility_date = "2024-10-11"
assets = { directory = "./public" }

# Workers Logs
# Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
# Configuration: https://developers.cloudflare.com/workers/observability/logs/workers-logs/#enable-workers-logs
[observability]
enabled = true

Configure the scripts section in the project’s package.json.

package.json
1
2
3
4
5
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev"
},

Run the command, and you should see a message indicating a successful deployment.


If you have any questions, feel free to leave a comment so we can discuss and learn together
If you found this article helpful, please respond with an emoji, leave a comment, or share it with more friends Thank you


Total Site Visits:times
This site was created by LinWhite using the Stellar 1.29.1 theme.
All articles on this site, unless otherwise stated, are licensed under the CC BY-NC-SA 4.0 license. Please credit the source when republishing.