0%

[筆記] GitHub pages + Hexo 搭建 Blog (Mac)

自己在建置的時候查了很多資料,整理完希望幫助到有需要的人
完整手把手教學 GitHub pages + Hexo 搭建

環境建置

安裝 Hexo

1
npm install -g hexo-cli

初始化 Hexo

安裝完 Hexo 後,執行下方指令,Hexo 就會在指定資料夾 中新建所需要的的檔案。

1
2
3
4
5
hexo init <folder name>
cd <folder name>
npm install
//安裝 git 部署套件
npm install hexo-deployer-git --save

啟動 Hexo

1
2
hexo g
hexo s
  • 指令介紹
    hexo generate (hexo g) 產生靜態檔案,會在目錄下產生public 資料夾
    hexo server (hexo s) 預覽、啟動伺服器,預設 http://localhost:4000/
    hexo deploy (hexo d) 部署網站 (EX: github, heroku … )

  • 常用組合
    hexo d -g # 產生靜態檔後部署
    hexo s -g # 產生靜態檔後預覽

網站配置 _config.yml

5 ~ 12 行

1
2
3
4
5
6
7
8
9
# Site
title:
subtitle: ''
// 內容描述(給搜尋引擎看的)
description: ''
keywords:
author:
language: en
timezone: ''

將 Hexo 配置到 GitHub

1
2
3
4
5
6
url: https://<username>.github.io/

deploy:
type: git
repo: https://github.com/<username>/<username></username>.github.io.git
branch: master
  • 若沒有 GitHub 帳號
    1. GitHub 申請
    2. 新建 Repositories 取名為 <blogname.github.io>.github.io

更換主題

可至 Themes 挑選,據說最多人用的是 NexT

  • 安裝 NexT

    1
    git clone https://github.com/theme-next/hexo-theme-next.git themes/next
  • 修改 _config.yml

    1
    theme: next ( default landscape )
  • 重新啟動 server

    1
    hexo server

新增文章

文章會以 Markdown 格式來撰寫,並且檔案存放在 /source/_posts/

1
hexo new "<title>"