本文记录如何通过Github的repo创建静态博客
Github中创建repository
- repo的name:
github用户名+github.io
,例如我的repoName:yangtang1996.github.io
- 勾选
Initialize this repository with a README
安装一些软件
- git
- node.js
软件正常安装,一路按照默认设置即可,完成后通过cmd或者powershell验证
git --version
node -v
npm -v
正确显示版本号就OK了
配置Git的SSH
- 配置Github账号
git config --global user.name "yourname"
git config --global user.email "youremail"
-
获取SSH密匙
通过下面代码判断本机是否已有密匙
cd ~/.ssh ls
-
第一次配置密匙
ssh-keygen -t rsa -C "xxxx@xxx.com"
-
读取已有密匙
cat ~/.ssh/id_rsa.pub
-
将读取的密匙 ssh-rsa ...... .com
复制并打开Github
Account - > setting - > SSH and GPG keys -> NEW
Title 任意即可
把刚才的密匙ssh-rsa ...... .com
添加到SSH key中
安装hexo
使用npm下载主题到默认的下载路径
npm install hexo-cli -g
在电脑上需要的地方新建Blog文件夹
进入该文件夹,初始化hexo到该Blog文件夹
hexo init
npm install
上传hexo到Github
在Blog文件夹内
hexo clean
hexo g
hexo d
也可以写一个dat脚本实现,保存在文件夹根目录下
@echo off
cd %~dp0
hexo clean && hexo g && hexo d
正确情况下,运行脚本会一边运行一边显示进度,有一定的时间延迟
如果脚本运行很快结束,则可能是存在问题,需要使用Git方法上传查看提示
安装NEXT主题
blog根目录下
git clone https://github.com/iissnan/hexo-theme-next themes/next
在_config.yml中设置
theme: next
正常设置在页面跳转时出现问题
有一处需要更改的地方,进入thems文件夹,找到next-> _config.yml
修改其中的menu为如下
menu:
home: /|| home
#about: /about/ || user
tags: /tags/|| tags
categories: /categories/|| th
archives: /archives/
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
最后运行脚本上传博客吧!