mac上用hexo在github上搭建个人博客的过程

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/w5688414/article/details/82713206

感想

其实我两年前也搭建过这个博客,到现在还是得乖乖的查资料,心想了想,技术一段时间不用,就会忘记,我还是把它记录下来,后面方便自己,也希望能够帮助到他人。

过程

安装

1.安装node.js

去官网直接下载,安装,node.js

2.安装git

由于我这里已经安装过了,我这里给个参考文献,安装过程也非常简单的。github配置ssh的过程我也忽略了,不配置也行,只是后面每次deploy的时候都需要输入用户名和密码;如果配置的话,就不需要每次都输入。这看读者的选择。

git安装

3. 安装hexo

前面我们已经安装了Node.js,这里我们使用npm命令来安装Hexo

npm install -g hexo

接着在任意位置创建一个文件夹,如blog,cd到该路径下执行以下命令

mkdir blog

接下来一波指令操作:

hexo init
npm install
hexo generate
hexo server

然后在浏览器上输入http://localhost:4000/ 就可以查看了。

扫描二维码关注公众号,回复: 4251193 查看本文章

本地的弄好了,我们接下来把本地的deploy到github上去

同步本地博客到Github

在github上新建个仓库,名为yourname.github.io,yourname是github的用户名

编辑自己创建的本地博客文件夹(我这里是blog文件夹下的)中的_config.yml中的deploy节点:

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repository: https://github.com/yourgithubname/yourgithubname.github.io.git
  branch: master

为了能够使Hexo部署到GitHub上,需要安装一个插件

npm install hexo-deployer-git --save

然后输入以下命令:

hexo clean
hexo generate
hexo deploy

这时打开你的在浏览器上看输入https://yourgithubname.github.io/就可以看啦,当然如果看到你想到的效果,这可能是github需要一定的时间部署,等一会儿看有没有变成你想要的样子。

发布新文章

这时候你想迫不及待的写文章了,这时我们需要输入:

hexo new post '文章标题'

就行了,然后在source/_posts/目录下就有创建的md文件,编辑就行了,编辑好后,按照我先前写的方法本地发布,或者deploy到github上。

更换主题

我在搭建完成后,第一件想干的事情就是把主题换掉,因为原生的主题实在是太丑了,这里,我在我的blog文件夹下:

https://hexo.io/themes/ 这个网站上找个你喜欢的主题,我这里找的是:

https://github.com/lyyourc/hexo-theme-again

在blog下打开终端:

git clone https://github.com/DrakeLeung/hexo-theme-again.git themes/again
npm i -S hexo-renderer-sass hexo-renderer-markdown-it markdown-it-emoji twemoji

然后修改blog目录下的config文件:

# config.yml
# theme: landscape
theme: again

就行了,这个主题当时的主题图片url失效了,我是这样修改的:

在blog/themes/again/目录下,修改config文件:

avatar: images/avatar.png
banner_small: images/banner-small.png
banner_large: images/banner-large.png
# avatar: http://7xrcp8.com1.z0.glb.clouddn.com/avatar.png
# banner_small: http://7xrcp8.com1.z0.glb.clouddn.com/banner-small.png
# banner_large: http://7xrcp8.com1.z0.glb.clouddn.com/banner-large.png

然后重新的发布在本地看就能够正常显示了,是不是很简单,前提是你懂git和hexo这个流程。

参考文献

[1].Mac下使用Hexo+Github搭建个人博客.https://www.jianshu.com/p/e5f95eb990ad

猜你喜欢

转载自blog.csdn.net/w5688414/article/details/82713206