hexo静态博客搭建与配置

搭建静态博客

windows用户:git bash +node环境

git安装

在官网下载对应版本号安装即可git官网下载地址

node环境安装

32位node下载地址:32位安装包
64位node下载地址:64位安装包

基本上点击下一步即可完成安装。
安装完成后cmd打开终端输入path查看环境变量中如果有nodejs、npm则表示已经安装成功node环境。Git表示git安装成功

这里写图片描述

接下来就是hexo的安装了。这个也非常简单
在git bash中输入以下命令:

1
$npm install hexo-cli -g

再创建一个hexo文件夹,在该文件夹目录下初始化hexo:

1
2
$ hexo init

安装依赖包:

1
2
$ npm install

如果在安装的过程中遇到错误:

1
ERROR Deployer not found : github

则输入下面这个命令

1
2
3
$ npm install hexo-deployer-git --save
$ hexo g
$ hexo d

再执行命令:

1
2
$ hexo g
$ hexo s

分别加载静态资源和开启服务器

然后用浏览器访问http://localhost:4000/,就能看到了一个漂亮的博客了,不过这个博客只是本地的,localhost是本机地址。hexo3.0使用的默认主题是landscape。如果觉得该主题不好看,github有很多star很多的主题可以参考。

本地文件推送到github

如果已经成功注册了github,接下来要做的就是将本地静态资源推送到github上。
首先配置_config.yml:

1
2
3
4
deploy:
type: git
repository: http://github.com/[name]/[name].github.io.git
branch: master

name中填写github用户名,并且两个name相同,需要小写,大写的话域名访问时也会默认为小写。

再输入:

1
2
$ hexo g
$ hexo d

将本地内容推送到github上。

接下来过几分钟在浏览器访问[name].github.io就能看到自己的博客了

主题修改

本人用了huno主题,大概长这样的,图片文字栏目都是可配置的

这里写图片描述

首先需要clone github资源到本地
例如这里演示huno主题的安装配置

1
$ git clone git://github.com/someus/huno.git themes/huno

修改Hexo的配置文件_config.yml:theme: huno

主题theme中的_config.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Header
menu:
首页: /#blog
关于: /about
归档: /archive
# Site favicon
favicon: /favicon.png
# Site logo
# logo: /avatar.png
# Enable Mathjax
mathjax: true
# Enable awesome-toc
awesome_toc: true
# Enable githubRepoWidget
github_repo_widget: false

###创建新page

1
2
3
4
5
# Header
menu:
首页: /#blog
关于: /about
归档: /archive

在主页展示中的page选项是可以配置的:

1
2
3
$ hexo new page archive
$ cd source/archive
$ vim index.md

也可以选择用其他编辑器打开,这里用了vim。
打开后修改内容为:

1
2
3
title: 归档
layout: page-archive
---

浏览器访问
http://127.0.0.1:4000/archive/即可。

“关于”页面的配置同理

新建博客文章

1
$ hexo new [name]

默认路径在hexo文件夹中的\source_post目录,打开【name】.md,打开方式使用记事本或notepad++。
hexo中写文章使用的是Markdown,这样会自动为文章添加目录

注意新建博客文章和page目录的不同

接下来就可以在漂亮的hexo博客中写文章啦~

Tips

在hexo中的md文件用markdown语法书写标题时,记着在“#”后加一个空格,否则这个标题语法将无效,右侧也不显示目录啦!