avatar

Mac系统下搭建hexo博客

mac系统下搭建hexo博客

1:前言

最近疫情很严重啊,在家里无聊到要发霉了,恰逢英雄联盟最近有无限火力,兴致勃勃的撸了几十把,确也索然无味了,想起来,这月还有一场要现场面的面试,不知道疫情是否影响,先做准备吧,以博客的方式,记录下准备的过程吧,那么,开始吧

(所用环境:macOS Mojave,nodejs,这些环境,Mac都是自带的)

2:搭建博客步骤

(1)GitHub上建立仓库

登录上GitHub(没有账号的自行注册),

new一个repositories(仓库)

仓库名最好设置成yourname.github.io,其他选项可默认

(2)本机安装hexo框架

在finder里建立一个文件夹来放置博客(推荐建立在macos/Users/yourname这个路径下)

打开终端(命令行),用cd命令cd到刚刚建立的文件夹下

输入npm install -g hexo cli,等待安装成功

初始化博客目录hexo init

开启本地服务hexo s

打开浏览器输入localhost:4000

至此,本地hexo安装算是告一段落了

3:push到GitHub,实现外网可以访问

(1)关联GitHub账号。实现免密push文章

生成本地ssh公钥,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#必须确保在根目录
cd ~
#生成密钥,接下来的三次输入全部回车
#ssh-keygen -t rsa -C "你登录GitHub用的邮箱"
sh-3.2# ssh-keygen -t rsa -C "yookbu@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/var/root/.ssh/id_rsa): (回车)
Enter passphrase (empty for no passphrase): (不想要密码,可直接回车)
Enter same passphrase again: (确认密码)
Your identification has been saved in /var/root/.ssh/id_rsa.
Your public key has been saved in /var/root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:2Ln5nn37eZ3j1M/lCT1owQvYxOkTh0W9xUf2UUHw44I yookbu@gmail.com
The key's randomart image is:
+---[RSA 2048]----+
| .++**|
| . + .o*|
| * . o=|
| o .= = ...|
| . S. E + . |
| o o * .|
| o = +=|
| . o. +=O|
| .+ ..o*B|
+----[SHA256]-----+
#至此,生成密钥成功,
#cd到.ssh下
sh-3.2# cd .ssh
sh-3.2# ls
.id_rsa.pub.swp id_rsa id_rsa.pub
#使用vi或vim打开公钥,复制公钥内容
sh-3.2# vi id_rsa.pub

复制完成后,输入:然后输入wq!退出

设置用户名和邮箱(与github一致即可)

1
2
3
sh-3.2# git config --global user.name “yookbu” 

sh-3.2# git config --global user.email “yookbu@gmail.com”

在GitHub配置公钥

)

验证配置ssh密钥是否成功

1
2
3
4
5
6
7
8
9
10
11
sh-3.2# ssh -T git@github.com

The authenticity of host 'github.com (52.74.223.119)' can't be established.

RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.

Hi yookbu! You've successfully authenticated, but GitHub does not provide shell access.

现在,本地的blog内容已经与GitHub仓库建立了连接,只需把本地的blog文件push到你的GitHub仓库即可

4博客的基础使用技巧

修改hexo配置文件(博客主目录下的–config。yml)

(直接放上我的配置文件,根据注释自行修改,最关键的是最后三行,一定要写对)

创建新的文章

1
2
sh-3.2# hexo new "mac系统下搭建hexo博客"
INFO Created: /Users/yookbu/blog/source/_posts/mac系统下搭建hexo博客.md

执行之后,在给定的路径下hexo自动创建了Markdown文档,打开,输入内容即可(推荐使用Typar去编辑使用)

发布文章

1
2
hexo g(生成静态页面)
hexo d(同步至GitHub个人仓库)

如果出现

1
2
sh-3.2# hexo d
ERROR Deployer not found: git

使用npm install --save hexo-deployer-git即可

可以先本地使用hexo s 命令,在本地通过localhost .4000来预览,没问题了在用hexo d 同步文档

5主题修改

hexo主题站里选择你喜欢的主题,点击进去,跳转到主题的GitHub仓库,你可以选择clone和download两种方式获得你喜欢的主题,

(1)clone

文章作者: yookbu
文章链接: http://www.yookbu.xyz/mac%E7%B3%BB%E7%BB%9F%E4%B8%8B%E6%90%AD%E5%BB%BAhexo%E5%8D%9A%E5%AE%A2/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 yookbu
打赏
  • 微信
    微信
  • 支付寶
    支付寶

评论