准备工作
- GitHub账号
- mac/pc
环境
node.js
git
创建GitHub仓库
登陆GitHub,创建一个新的Respository
Repository name叫做{username}.github.io
{username}
代表你的GitHub用户名,Repository name一点要叫这个
绑定域名
待定
绑定ssh秘钥
- 设置git用户名和邮箱
git config --global user.name "liuxianan"// 你的github用户名,非昵称
git config --global user.email "[email protected]"// 填写你的github注册邮箱
- 生成ssh秘钥
ssh-keygen -t rsa -C "邮件地址"
连续3次回车,不需要输入密码
公钥文件在在用户目录下.ssh\id_rsa.pub
- 进入
github -> settings -> SSH and GPG keys
,点击new SSH key
,将id_rsa.pub
中的内容复制到其中,并确定,这样只要使用生成秘钥的电脑git访问GitHub是都不需要再输入用户名密码
安装Hexo
Hexo本体和部署插件
npm install -g hexo
npm install hexo-deployer-git --save
博客初始化
进入选的的文件夹
hexo init
此时会生成blog
文件夹,这就是hexo默认的博客
cd blog
hexo g # 生成
hexo s # 启动服务
此时可以本地启动博客,去浏览器打开网址即可,默认是localhost:4000
可以看到一篇Hello World
的文章
默认主题很简洁,想要更喜欢的主题可以去官网寻找https://hexo.io/themes/
主题选择
本次博主选择主题https://www.huweihuang.com/
GitHub地址https://github.com/huweihuang/hexo-theme-huweihuang
- init
git clone https://github.com/huweihuang/hexo-theme-huweihuang.git ./hexo-huweihuang
cd hexo-huweihuang
npm install
- 编辑配置文件
hexo-huweihuang/_config.yml
根据自己的喜好修改配置文件
以下配置仅针对该主题博客,其他的主题配置可能有所不同!
# Site
title: {标题}
subtitle: {副标题}
author: {作者名字}
# 下面的配置注释掉,是绑定域名的相关配置,以后也可以改成自己的域名
url: http://www.huweihuang.com/
root: /
# Site settings,在页面底部,酌情填写
SEOTitle: {作者名} | Blog
email: {邮箱}
# 填写你的GitHub用户名
github_username: {username}
# 以下为默认内容,可以先注释掉,也可以改成自己的相关网址
# 最外层的`friends:[]`不能注掉
friends: [
{
title: "CSDN Blog 胡伟煌",
href: "http://blog.csdn.net/huwh_"
},
{
title: "DockOne 胡伟煌",
href: "http://dockone.io/people/胡伟煌"
},
{
title: "阿里云栖社区 胡伟煌",
href: "https://yq.aliyun.com/u/huweihuang"
}
]
# github仓库的ssh地址,{username}代表你的github用户名
# {msg}代表你对每次部署的描述内容,相当于git commit -m 后面加的描述内容,可以不填
deploy:
type: git
repository: git@github.com:{username}/{username}.github.io.git
branch: master
message: {msg}
- 本地预览
cd hexo-huweihuang
hexo g
hexo s
打开localhost:4000
,可进行预览
评论功能
待定
编写markdown博客
新建markdown文件
开头如下,以下是本篇博客的例子
tags
是标签,可自行添加
top
填1表示置顶,0表示不置顶
标题和时间可自行修改
---
title: "Hexo和github搭建个人博客"
catalog: true
toc_nav_num: true
date: 2019-07-06 10:51:24
subtitle: "你的博客你做主"
header-img: "/img/article_header/article_header.png"
tags:
- Hexo
- Github
catagories:
- Hexo
updateDate: 2019-07-06 22:26:24
top: 0
---
接下来就可以编写正文了…
markdown文件要放在hexo-huweihuang/source/_posts
文件夹中
部署博客
cd hexo-huweihuang
hexo g
hexo d # deploy部署
也可使用
hexo g -d
或者hexod -g
如果有些奇怪的问题可以
hexo clean
清除已经生成的部署文件,再重新执行
结束
访问{username}.github.io
即可访问你的私人博客
如果绑定域名也可通过域名访问