GitHub域名:https://github.com/zff-excellent
博客地址:https://zff-excellent.github.io/
谢益辉的博客:https://yihui.org/
零、前期准备
- 自建博客的原因,树立个人品牌
为什么应该从现在开始写博客
为什么自建博客
教你免费搭建个人博客,Hexo & GitHub
免费快速搭建博客教程 Hexo & GitHub - 环境配置
安装Node.js
安装Git for Windows
git教程
安装cmder
安装Sublime Text - 注册github账号
登录https://github.com/
一、配置GitHub
- 首先注册、登录GitHub: https://github.com/(没有的就注册一个)
- 保留自己Username,zff-excellent
- 主页中点击右上角Create a new repository: https://github.com/new
- 点击repositories,新建一个
- Repository name (填自己的名字) http://yourname.github.io(yourname与你的注册用户名一致,这个就是你博客的域名了), 写入zff-excellent.github.io
例如,我的域名是https://github.com/zff-excellent,就填入zff-excellent.github.io
二、环境配置 (node/git)
-
安装Node.js,用来生成静态页面
检查node.js是否安装
node -v
npm -v -
安装Git for Windows, 用来把本地的hexo内容提交到github上去
git教程 - 安装git完成后,在开始菜单里找到“Git”->“Git Bash”,进入
git config –global user.name “zff-excellent”
git config –global user.email “zhaofenfei2015@163.com” - 安装Sublime Text
- 安装cmder
- cmder中输入npm install -g hexo-cli --force(管理员权限)
npm install -g hexo-cli --force
三、网站设置
- 在H盘中新建文件夹test,管理员权限打开cmder
H: #进入H盘
cd test #进入test目录
hexo init blog
_config.yml,备份该文件_config_template.yml。网站的 配置 信息,可以在此配置大部分的参数。
source文件夹,资源文件夹是存放用户资源的地方。除 posts 文件夹之外,开头命名为 (下划线)的文件 / 文件夹和隐藏的文件将会被忽略。Markdown 和 HTML 文件会被解析并放到 public 文件夹,而其他文件会被拷贝过去。
public文件夹,已经public的文档;
themes文件夹。Hexo 会根据主题来生成静态页面。
- mention: INFO Start blogging with Hexo!,表示安装hexo成功了。
- 初始化hexo之后,source目录下自带一篇文章
- cmder命令行进入blog目录下,cd blog
- 输入hexo generate,生存静态文件
- 输入hexo server,启动本地服务器。在浏览器中输入http://localhost:4000/,就可以看见网页和模板了
- 发布本地网页到github上。
访问http://localhost:4000/,便可以看到网站初步的模样,我们还要把网页发布到Github上去。
重新打开CMD,输入ssh-keygen -t rsa -C "Github的注册邮箱地址" #zhaofenfei2015@163.com
一直Enter过来,得到信息:
Enter same passphrase again:
Your identification has been saved in /c/Users/whbio/.ssh/id_rsa
Your public key has been saved in /c/Users/whbio/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:f6+AptvQqUdGDhP2Ww8bZY/u2tIyKUmoDtY2s6/pM94 zhaofenfei2015@163.com
3.png - 设置github上的ssh key
找到id_rsa.pub文件,打开Ctrl + A复制里面的所有内容,然后进入Sign in to GitHub:https://github.com/settings/ssh
New SSH key ——Title:blog;Key:输入刚才复制的—— Add SSH key
四、编辑博客
- 进入blog网站,用sublime打开_config.yml文件(博客基本配置信息),修改参数。每个参数的:后都要加一个空格(这个坑踩的我头晕)
- 修改Site部分
# Site
title: 赵芬菲的博客
subtitle: ''
description: ''
keywords:
author: zhaofenfei
language: zh-CN
timezone: Asia/Shanghai
- 修改deploy部分
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
# https://github.com/zff-excellent/zff-excellent.github.io.git
repo: git@github.com:zff-excellent/zff-excellent.github.io.git
branch: master
五、发表博客
- 打开cmder,进入blog文件夹下,输入hexo new “Hello blog”# 输入博客名
- 在source目录下,找到新建的该博客
- 用sublime Test打开文件,采用Markdown语法进行编辑
Markdown编辑使用说明 - 编辑完成后,在cmder中执行以下步骤
hexo clean
hexo generate
hexo server - 在浏览器中输入http://localhost:4000/,本地没问题后部署到服务器上
- hexo deploy
ERROR1: deployer not found:github
Solution: npm install hexo-deployer-git --save
ERROR2: SSL certificate problem: self signed certificate in certificate chain
Solutution解决ssh不信任
repo: https://github.com/zff-excellent/zff-excellent.github.io.git # wrong
repo: git@github.com:zff-excellent/zff-excellent.github.io.git # right
4.png