使用Hexo建立个人Blog站

本文章记录了本博客的建立过程,以下所有操作是在Manjaro Linux上进行的,其他未尽事宜请见官方文档

Hexo简介

Hexo是一个快速、简洁且高效的博客框架;

可以使用 Markdown 来排版和写文章;

生成的网页是静态页面的,特别适合用来白嫖 GitHub Pages😈。

安装环境

Hexo运行所需的软件和安装命令如下:

  • Node.js

    1
    yay -Sy nodejs npm

    由于某些不可描述的原因,npm需要换成国内的淘宝源:

    1
    npm config set registry https://registry.npm.taobao.org
  • Git

    1
    yay -Sy git

Hexo站点初始化

建立一个空文件夹并进入这个文件夹,这将成为博客站的主目录

1
mkdir hexo_blog && cd hexo_blog

在该目录内安装Hexo

1
npm install hexo

进行hexo初始化

1
npx hexo init

此时,一个Hexo驱动的博客站就建好了。要查看刚刚建好的博客,可以执行npx hexo clean && npx hexo g && npx hexo s,按住Ctrl建点击生成的网址即可打开。

Hexo管理

这里列举几个常用的Hexo命令

  • 清理生成的文件

    1
    npx hexo clean
  • 生成文件

    1
    npx hexo generate
  • 进行预览

    1
    npx hexo server
  • 新建文章

    1
    npx hexo new "NewPostName"

Hexo主题修改

Hexo有很多主题可供选择,在官网的主题站挑选,这里选择pure主题

在博客站主目录下克隆主题

1
git clone https://github.com/cofess/hexo-theme-pure.git themes/pure

安装pure主题的依赖包

1
2
3
4
5
npm install hexo-wordcount --save
npm install hexo-generator-json-content --save
npm install hexo-generator-feed --save
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save

复制一份主题配置样例到博客主目录

1
cp themes/pure/_config.yml _config.pure.yml

修改博客配置_config.yml,将themes: landscape修改为themes: pure

根据说明文档对主题配置进行相关修改。

Hexo部署

登录自己的GitHub,新建一个Repository,名字为[GitHub用户名].github.io

在Repository的Setting中勾选GitHub Pages功能。

打开博客配置文件_config.yml修改博客网站的描述部分

1
2
3
4
5
6
7
8
9
# Site
title: HulGodhel's Blog # 博客标题
subtitle: '' # 次标题
description: '' #网站描述
keywords: # 关键词
author: HulGodhel # 作者
language: en # 博客网站语言,英语en,中文zh-CN
timezone: '' # 时区

修改站点网址部分

1
2
3
4
# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://[Github用户名].github.io

修改部署部分

1
2
3
4
deploy:
type: 'git' # 部署方式为git
repository: git@github.com:happylzyy/happylzyy.github.io.git # Repository远程仓库地址
branch: master # 部署到远程分支master

配置完成后,运行npx hexo clean && npx hexo g重新生成博客,再运行npx hexo deploy即可部署到GitHub上。