用hexo+icarus搭建个人博客
如何用Hexo+Icarus建立一个个人网站
前置准备
在开始建立个人网站前,需要安装以下工具:
Node.js 和 npm
- 下载地址:Node.js官网
- 安装后,在终端运行以下命令验证安装成功:
1
2node -v
npm -v
Git
- 下载地址:Git官网
- 安装后,在终端运行以下命令验证安装成功:
1
git --version
GitHub账号
- 如果你打算部署到GitHub Pages,需要一个GitHub账号
- 注册地址:GitHub
安装Hexo
全局安装Hexo-CLI
1
npm install -g hexo-cli
创建Hexo项目
1
2
3hexo init my-blog
cd my-blog
npm install安装必要的插件
1
2npm install hexo-renderer-inferno --save
npm install hexo-deployer-git --save
安装Icarus主题
安装Icarus主题
1
npm install hexo-theme-icarus --save
启用Icarus主题
- 在根目录下的
_config.yml
中修改主题设置:1
theme: icarus
- 或者使用以下命令自动创建主题配置文件:
1
hexo config theme icarus
- 在根目录下的
个性化配置
基本配置
修改
_config.yml
文件- 站点名称、作者、URL等基本信息
1
2
3
4
5
6
7title: 你的网站标题
subtitle: '副标题'
description: '网站描述'
keywords: 关键词
author: 你的名字
language: zh-CN
timezone: 'Asia/Shanghai'配置部署信息
==注意,这里的
repo
必须为github仓库中以github.io结尾的仓库名字==1
2
3
4deploy:
type: git
repo: git@github.com:用户名/用户名.github.io.git
branch: master
Icarus主题配置
修改
_config.icarus.yml
文件==注意,在
publish
文件下的内容全部是自动生成的内容,对这个文件下的内容做的所有修改都是无效的。以及所有_config.icarus.yml
中的相对寻址路径都是在public
下去寻找的。如果要添加自己的图片,请在source
下新建img
文件,放入图片,你会在publish对应的文件夹下面看见你放入的文件。更多详情请见icarus和hexo的官方文档==配置网站logo和图标
1
2
3logo: /img/logo.svg
head:
favicon: /img/favicon.svg #在public下的img文件夹中去寻找图标配置导航菜单
1
2
3
4
5
6
7navbar:
menu:
首页: /
归档: /archives
分类: /categories
标签: /tags
关于: /about配置侧边栏
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28sidebar:
left:
sticky: true
right:
sticky: true
widgets:
-
position: left
type: profile
author: 你的名字
author_title: 你的职位
location: 你的位置
avatar: /img/avatar.jpg
-
position: left
type: toc
-
position: left
type: categories
-
position: left
type: recent_posts
-
position: left
type: archives
-
position: left
type: tags调整主栏宽度
- 如果想让主栏更宽,可以将所有widget放在同一侧(如左侧)。可以参考常见问题 - Icarus (ppoffice.github.io)
配置Gitalk评论系统
如果你没有有自己的OAuth应用:注册GitHub OAuth应用
- 访问 https://github.com/settings/applications/new
- 填写应用名称(如”博客评论”)
- 主页URL:你的博客地址
- 回调URL:与主页URL相同
- 点击”Register application”
如果你已经有自己的OAuth应用:查看已创建的OAuth应用
- GitHub头像 -> Settings -> Developer settings -> OAuth Apps
配置Gitalk
- 在
_config.icarus.yml
中添加:
1
2
3
4
5
6
7
8comment:
type: gitalk
client_id: 你的client_id
client_secret: 你的client_secret
repo: 用户名.github.io
owner: GitHub用户名
admin:
- GitHub用户名- 在
初始化评论
- 部署网站后,以管理员身份登录并访问每篇文章,初始化对应的GitHub Issue
创建内容
创建新文章
1
hexo new "文章标题"
文章格式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15---
title: 文章标题
date: 2023-03-18
categories:
- 分类1
- 分类2
tags:
- 标签1
- 标签2
excerpt: 这是文章摘要,会显示在首页。
---
<!-- more -->
这里是文章正文内容...
本地预览
启动本地服务器
1
hexo server
访问本地预览
- 浏览器打开 http://localhost:4000
部署网站
生成静态文件
1
2hexo clean
hexo generate #或者直接 hexo g部署到GitHub Pages
1
hexo deploy #或者直接 hexo d
自定义域名(可选)
- 在
source
目录下创建CNAME
文件,内容为你的域名 - 在域名提供商处设置DNS解析到GitHub Pages
- 在
常见问题解决
主题配置问题
- 确保YAML格式正确,注意缩进
- 使用在线YAML验证工具检查格式
图片显示问题
- 将图片放在
source/img/
目录下 - 路径使用
/img/图片名.jpg
- 将图片放在
Gitalk初始化问题
- 确保client_id和client_secret正确
- 检查repo名称是否正确
- 需要管理员登录GitHub并访问文章页面初始化评论
参考资源
用hexo+icarus搭建个人博客