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

0. 準(zhǔn)備環(huán)境

  • git
  • Node.js
  • github 賬號

1. 安裝

1.1 安裝 git

Git下載地址

一路 next 沒啥好說的

驗證一下,在命令行下執(zhí)行

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

就說明成功了

1.2 安裝 Node.js

Node.js下載地址

一路 next 沒啥好說的

驗證一下,在命令行下執(zhí)行

D:\GitRepository>node -v
v6.11.5

D:\GitRepository>npm -v
3.10.10

1.3 安裝 Hexo

npm install -g hexo-cli 

2. 創(chuàng)建本地Blog

在命令行下進入一個空文件夾內(nèi),

執(zhí)行

hexo init

本地blog就創(chuàng)建成功了

執(zhí)行

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 站內(nèi)搜索

安裝 hexo-generator-search 插件。

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

search:
    use: local
    swiftype_key: 

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

search:
    path: search.xml
    field: all

其他相關(guān)配置可查看文檔

4. 提交部署

在github上創(chuàng)建 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

創(chuàng)建blog模板

hexo new 這是我的第一篇文章

會在 source/_posts 目錄下創(chuàng)建一個md文件??梢跃庉嬤@個文件創(chuàng)作blog

6. 多臺機器

有時候需要在不同的地方寫blog。這就需要在多臺機器上同步 blog。

主要思路是創(chuàng)建兩個分支,一個用于管理blog,一個用于管理原文件

在blog目錄下

6.1 創(chuàng)建源文件git目錄

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

6.2 創(chuàng)建 source 分支

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

6.3 多機器同步

clone 倉庫到本地

初始化 Hexo。跟上面的步驟一樣,不再贅述。注意分支的切換

7 分類 &標(biāo)簽

7.1 創(chuàng)建分類

執(zhí)行

 hexo new page categories

打開 source/categories/index.md

修改為:

---
title: 文章分類
date: 2017-05-27 13:47:40
type: "categories"
---

7.2 給文章添加分類

---
layout: hexo
title: Hexo + Material + Github 搭建博客與配置
date: 2018-03-26 13:22:22
categories: 
- 工具
tags: 學(xué)習(xí)筆記
---
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容