0%

hexo+github搭建个人博客

hexo+github搭建个人博客

注:以下内容在manjaro系统操作

1、安装git、nodejs、npm

1
sudo pacman -S git npm nodejs

2、注册github帐号并配置

​ 注册github帐号后,新建一个 <你的用户名.github.io> 的仓库(repository)

配置:

1
cd ~/. ssh #检查本机已存在的ssh密钥

如果提示:No such file or directory 说明你是第一次使用git。

1
ssh-keygen -t rsa -C "邮件地址"

然后连续3次回车,最终会生成一个文件在用户目录下,打开用户目录,找到.ssh\id_rsa.pub文件,记事本打开并复制里面的内容,打开你的github主页,进入个人设置 -> SSH and GPG keys -> New SSH key,将刚复制的内容粘贴到key那里,title随便填,保存。

测试是否成功:

1
ssh -T git@github.com # 注意邮箱地址不用改

如果提示Are you sure you want to continue connecting (yes/no)?,输入yes,然后会看到:

Hi xxx! You’ve successfully authenticated, but GitHub does not provide shell access.

看到这个信息说明SSH已配置成功!

此时你还需要配置:

1
2
git config --global user.name "github用户名"
git config --global user.email "邮箱地址"

3、安装hexo

1
npm install -g hexo-cli

4、安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件。

1
2
3
hexo init <folder>
cd <folder>
npm install

新建完成后,指定文件夹的目录如下:

1
2
3
4
5
6
7
8
.
├── _config.yml #网站的 配置 信息,您可以在此配置大部分的参数。
├── package.json #应用程序的信息。
├── scaffolds #模版 文件夹。当您新建文章时,Hexo 会根据 scaffold 来建立文件。
├── source #资源文件夹是存放用户资源的地方。
| ├── _drafts
| └── _posts
└── themes #主题 文件夹。Hexo 会根据主题来生成静态页面。

5、安装主题

1
2
3
cd <folder>
git clone github主题地址.git themes/主题名
#推荐主题:git clone https://github.com/theme-next/hexo-theme-next themes/next

6、配置_config.yml

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

1
theme: 主题名

修改博客信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Site
title: Ryan'Blog #博客名
subtitle: '' #副标
description: '' #描述
keywords: #关键词
author: Wonder-Ryan #作者
language: zh-CN #语言
timezone: '' #时区
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://wonder-ryan.coding.me #博客地址
root: / #网站根目录
permalink: :year/:month/:day/:title/ #博客文章永久链接
permalink_defaults:
pretty_urls:
trailing_index: true # 去除博客文章链接的index.html后缀
#deploy配置
deploy:
type: git
repo: https://github.com/<username>/<project>
# 例如, https://github.com/hexojs/hexojs.github.io
branch: master

如果你没有pug以及stylus的渲染器,请下载安装:

1
2
3
npm install hexo-renderer-pug  hexo-renderer-stylus --save 
或者
yarn add hexo-renderer-pug hexo-renderer-stylus

7、deploy配置

1
2


7、安装部署工具

1
2
cd <博客目录>
npm install hexo-deployer-git --save

server工具

1
npm install hexo-server--save

hexo命令:

clean

1
hexo clean

清除缓存文件 (db.json) 和已生成的静态文件 (public)。

在某些情况(尤其是更换主题后),如果发现您对站点的更改无论如何也不生效,您可能需要运行该命令。

generate

1
hexo generate

生成静态文件。该命令可以简写为

1
hexo g

server

1
hexo server

启动本地预览服务。默认情况下,访问网址为: http://localhost:4000/ 预览一下,如果没有问题就可以 hexo deploy 部署到网站上了

deploy

1
hexo deploy

部署网站。该命令可以简写为:

1
$ hexo d
参数 描述
-g, --generate 部署之前预先生成静态文件
-------------本文结束感谢您的阅读-------------