Hexo + Material + Github 搭建博客与配置

Hexo + Material + Github 搭建博客与配置

0. 准备环境

  • git
  • Node.js
  • github 账号

1. 安装

1.1 安装 git

Git下载地址

一路 next 没啥好说的

验证一下,在命令行下执行

D:\GitRepository>git --version
git version 2.13.2.windows.1

就说明成功了

1.2 安装 Node.js

Node.js下载地址

一路 next 没啥好说的

验证一下,在命令行下执行

D:\GitRepository>node -v
v6.11.5

D:\GitRepository>npm -v
3.10.10

1.3 安装 Hexo

npm install -g hexo-cli 

2. 创建本地Blog

在命令行下进入一个空文件夹内,

执行

hexo init

本地blog就创建成功了

执行

hexo g
hexo s

访问 http://localhost:4000/ 就能看到自己的blog了。

3. 主题安装

这里使用的是 viosey 主题

3.1 下载主题:

cd themes
git clone https://github.com/viosey/hexo-theme-material.git material

3.2 使用主题:

修改主目录下的 _config.yml 文件的 theme 值,改为 git 克隆下来的文件夹名称。

重命名 theme/material 目录下_config.template.yml_config.yml

3.3 站内搜索

安装 hexo-generator-search 插件。

修改theme/material 目录 _config.yml 中的 search值

search:
    use: local
    swiftype_key: 

然后在主目录_config.yml文件中添加

search:
    path: search.xml
    field: all

其他相关配置可查看文档

4. 提交部署

在github上创建 xxxx.github.io仓库,其中xxxx是你github的用户名

安装 hexo-deployer-git

npm install hexo-deployer-git --save

配置主目录_config.yml文件

deploy:
  type: git
  repo: 仓库地址
  branch: master

部署到github

hexo d -g

访问下 https://xxxx.github.io/。试试(xxxx是你自己的用户名)

5. 写blog

创建blog模板

hexo new 这是我的第一篇文章

会在 source/_posts 目录下创建一个md文件。可以编辑这个文件创作blog

6. 多台机器

有时候需要在不同的地方写blog。这就需要在多台机器上同步 blog。

主要思路是创建两个分支,一个用于管理blog,一个用于管理原文件

在blog目录下

6.1 创建源文件git目录

 git init
 git remote add origin https://github.com/xx/xx.github.io // 填入你的repo地址

6.2 创建 source 分支

 git checkout -b source
 git add .
 git commit -m 'add source'
 git push origin source

6.3 多机器同步

clone 仓库到本地

初始化 Hexo。跟上面的步骤一样,不再赘述。注意分支的切换

猜你喜欢

转载自blog.csdn.net/u013451048/article/details/79696877
今日推荐