blog

Hexo+Github免费搭建个人博客

效果浏览:我的博客

安装Git和Node.js

直接去GitNode.js官网下载,下载较简单,这里不赘述。

安装Hexo

命令行输入即可

1
npm install -g hexo-cli

Hexo初始化

新建一个文件夹,可名为Blog,方便后期管理,(不想要可删掉从来),进入文件夹目录下执行如下命令:

1
2
hexo init
npm install

运行成功后我们可以发现文件夹下新增了很多文件
其中含有_config.yml文件 ,这个文件就是网站主题的的配置文件,后面和github page关联和切换主题时,需要使用到。

生成静态文件和开启服务

1
2
hexo g
hexo s

ctrl+c 关闭本地服务器
打开 http://localhost:4000/ 即可看到你的博客雏形。
当然,这个只能在本地访问。

注册Github账号、新建一个仓库

注意:

  • 尾缀必须是github.io
  • 仓库名必须和Owner名一致

比如我的:

配置SSH

新建成功后,复制ssh,打开Blog文件夹目录下的_config.yml文件并按照以下更改:

1
2
3
4
deploy:
type: git
repository: 你的ssh
branch: master

创建文章

命令行执行

1
hexo new post <title>

默认在source/_post/新建一个markdown文件,用md语法编辑即可。

post 新建文章 /source/_posts/
draft 新建草稿 /source/_drafts/
page 新建页面(标签页,分类页等) /source/

更换主题

Hexo主题选择你喜欢的主题,在Blog目录下执行以下命令即可下载

1
git clone https://github.com/litten/hexo-theme-xxx.git themes/xxx

下载成功后即可发现themes文件夹中多了你刚下载的主题。

此时,需将Blog文件夹目录下的_config.yml文件中的theme 修改为theme: xxx,(需要注意的是冒号后有空格)

部署到Github

安装hexo的部署插件

1
npm install hexo-deployer-git --save

生成静态文件并部署

1
2
hexo g
hexo d

当然你也可以先hexo s浏览一下再部署。

这样你便拥有了属于你个人的博客
https://bingoyyj.github.io/

主题优化

配置categories和tags

命令行:

1
2
hexo new page "tags" 
hexo new page "categories"

编辑 /tags/index.md

1
2
type: "tags"
layout: "tags"

编辑/categories/index.md

1
2
type: "categories"
layout: "categories"

给文章分类和贴标签

1
2
3
4
5
6
7
8
9
10
---
title: test
date: 2020-04-07 17:19:57
categories:
- 博客教程
tags:
- Hexo
- Github
- 主题
---

一篇文章一般分类只一种,标签可多个。

本地图片

在source文件夹新建一个img文件夹存放图片,md文件用相对路径访问即可,如:

1
![](../img/1.jpg)

更多主题优化

更多主题优化在themes文件夹的_config.yml文件中,可根据个人喜好进行更改.

Reward
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • © 2019-2020 Bingoyyj
  • Powered by Hexo Theme Ayer
  • PV: UV:

什么?这次一定?

支付宝
微信