Hexo搭建Github静态博客

Hexo搭建Github静态博客

安装环境

1.安装Git

2.安装node.js

下载并默认安装即可

3.配置Github

新建仓库并配置好SSH-Key

4.安装Hexo

4.1安装

打开Git Bash,输入以下命令:

1
$ npm install -g hexo

由于墙的原因,这一步一般都不会成功,所以使用npm国内镜像,执行以下命令:

1
$ npm config set registry https://registry.npm.taobao.org

然后再

1
$ npm install -g hexo

4.2启动

4.2.1新建Hexo文件夹

在电脑中新建一个Hexo文件夹,如 D:\Hexo ,然后在此文件夹内打开Git Bash,执行一下命令:

1
2
$ hexo init
$ npm install
4.2.2新建博客

在Git Bash里执行以下命令:

1
2
$ hexo new post "My Blog"
[info] File created at d:\Hexo\source\_posts\My-Blog.md

就可以对d:\Hexo\source_posts\My-Blog.md进行编写了

4.2.3启动服务

在Git Bash里执行以下命令:

1
2
$ hexo generate
$ hexo Server

就可以在浏览器里访问博客了,地址是:http://localhost:4000

4.3配置Hexo的_config.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
# Site
title: 博客的标题
subtitle: 博客的说明文字
description: 博客的说明文字
author: 博客的作者
language: 语言,一般中文是zh-Hans
timezone:


deploy:
type: git #新版本是Git,旧版本是GitHub,在部署到GitHub上可能会有错误
repository: git@github.com:user-name/user-name.github.io.git
branch: master

5.将Hexo部署到Github上

在Git Bash中执行以下命令:

1
2
$ hexo generate
$ hexo deploy

可能会出现error deployer not found:github 的错误,解决办法是:

1
npm install hexo-deployer-git --save

然后执行以上命令即可

至此Hexo已经搭建好了GitHub博客了,可以通过http://user-name.github.io访问

6.Hexo常用命令

1
2
3
4
5
6
$ hexo new post "post-name" #新建文章
$ hexo new page "page-name" #新建页面
$ hexo generate #生成静态页面至public目录,简写:hexo g
$ hexo servler #开启预览访问端口,简写:hexo s
$ hexo deploy #将.deploy目录部署到GitHub,简写:hexo d
$ hexo clean #清楚缓存,简写:hexo c

更多Next主题的问题点击这里