文章目录
hexo+github搭建博客
我的博客地址
- https://krismile.love/
效果展示
hexo、github
Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。
官网:https://hexo.io/zh-cn/
GitHub是一个面向开源及私有软件项目的托管平台
官网:https://github.com
博客搭建成功后,无需关心网页源代码的具体细节,只需要用心写好博客内容就行。
安装
- node.js
- Git
- vscode(个人偏好)
安装Git
Git是一个开源的分布式版本控制系统,在此教程中可以把本地的文件上传到Github上
Windows
- https://git-scm.com/download/win
安装完成之后,右键即可看到Git bash
,安装成功。
安装vscode
官网下载安装
https://code.visualstudio.com/
vscode配置git
我个人比较喜欢vscode编辑,不在vscode中,右键使用git bash
也可以,或者安装Windows terminal
配置git同样可以。
vscode中配置git bash
具体步骤如下:
-
vscode界面右下角设置图标–设置
-
在出现的搜索框中搜索
git.path
–打开在settings.json中编辑
-
找到安装的
git.exe
的安装为止复制到settings.json
中,用双斜杠替换单斜杠,不然会报错
-
把终端设置成
git bash
,在用户设置的搜索框中搜索terminal.integrated.shell.windows
,在settings.json
中打开 -
复制安装目录下的
bash.exe
路径,如图:
-
设置完以后就可以ctrl+`打开终端。
安装node.js
没有梯子的话可以,使用阿里云淘宝镜像加速,不过要使用github,还是建议去配一个代理。
npm config set registry https://registry.npm.taobao.org
官方给出的版本建议是Node.js 版本需不低于 10.13,建议使用 Node.js 12.0 及以上版本
下载地址:https://nodejs.org/zh-cn/
默认选择,一路下一步
安装完成后,打开终端运行node -v
和npm -v
,运行出现对应的版本号,则说明安装成功。
github page
去github注册一个账号,有账号的话,新建一个仓库,输入项目的名字,!!!项目名称后一定要跟.github.io
,EADME初始化也要勾上。名称一定要和你的github名字完全一样,比如你github名字叫abc,那么仓库名字一定要是abc.github.io。像我的:
完成之后,点击settings
,找到page
,点击上面出现的网址就可以访问github page了(这里已经绑定了域名,未绑定的话应该是krismile123.github.io)
安装hexo
进入到你想存放博客的文件夹下,运行
npm i hexo-cli -g
安装完成后输入hexo -v
验证是否安装成功
然后初始化网站,运行hexo -init
初始化文件夹,接着运行npm install
安装必备的组件。
运行完成后,测试一下,hexo g
生成静态文件,hexo s
打开本地服务器
访问http://localhost:4000/可以看到效果
github配置git
Windows
- 使用Git Bash生成新的ssh key
$ ssh-keygen -t rsa -C "xxxxxx@yy.com" #建议填写自己真实有效的邮箱地址
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxx_000/.ssh/id_rsa): #不填直接回车
Enter passphrase (empty for no passphrase): #输入密码(可以为空)
Enter same passphrase again: #再次确认密码(可以为空)
Your identification has been saved in /c/Users/xxxx_000/.ssh/id_rsa. #生成的id_rsa文件为密钥
Your public key has been saved in /c/Users/xxxx_000/.ssh/id_rsa.pub. #生成的id_rsa.pub公钥
The key fingerprint is:
e3:51:33:xx:xx:xx:xx:xxx:61:28:83:e2:81 xxxxxx@yy.com
- 添加ssh key到GItHub
-
登录GitHub账号;点击右上角账号头像的“▼”→Settings→SSH kyes→Add SSH key。
-
复制id_rsa.pub的公钥内容。
-
进入c:/Users/xxxx_000/.ssh/目录下,打开id_rsa.pub文件,全选复制公钥内容。
-
Title自定义,将公钥粘贴到GitHub中Add an SSH key的key输入框,最后“Add Key”。
- 配置账户
$ git config --global user.name “your_username” #设置用户名
$ git config --global user.email “your_registered_github_Email” #设置邮箱地址(建议用注册giuhub的邮箱)
- 测试ssh keys是否设置成功
$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.252.129)' can't be established.
RSA key fingerprint is 16:27:xx:xx:xx:xx:xx:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes #确认你是否继续联系,输入yes
Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/xxxx_000/.ssh/id_rsa': #生成ssh kye是密码为空则无此项,若设置有密码则有此项且,输入生成ssh key时设置的密码即可。
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access. #出现词句话,说明设置成功。
git 设置和取消代理
git config --global http.proxy 'socks5://127.0.0.1:7890'
git config --global https.proxy 'socks5://127.0.0.1:7890'
git config --global --unset http.proxy
git config --global --unset https.proxy
绑定域名
域名自己到各种云上面去买
购买完成后,添加两条解析记录
然后回到刚刚打开github page的页面上,找到custom domain,在下面填入你的域名
这是项目根目录下会出现一个CNAME的文件,如果没有的话,打开你本地博客/source目录,我的是D:\study\program\blog\source,新建CNAME文件,注意没有后缀。然后在里面写上你的域名,保存。最后运行hexo g、hexo d上传到github。
主题
我使用的是这一款主题matery,安装配置过程作者说的比较详细,按部就班就好。
写文章、发布博客
首先在博客根目录下右键打开git bash
,安装一个扩展npm i hexo-deployer-git
。
然后输入hexo new post "article title"
,新建一篇文章。
然后打开blog\source\_posts
的目录,可以发现下面多了一个文件夹和一个.md文件,一个用来存放你的图片等数据,另一个就是你的文章文件啦。
编写完markdown文件后,根目录下输入hexo g
生成静态网页,然后输入hexo s
可以本地预览效果,最后输入hexo d
上传到github上。这时打开你的github.io主页就能看到发布的文章啦。
reference
- https://godweiyang.com/2018/04/13/hexo-blog/
- https://github.com/blinkfox/hexo-theme-matery