# GitHub pages + Hexo 搭建 Blog (Mac) ### 環境建置 - 安裝 [Node.js](https://nodejs.org/en/) ```cmd brew install node ``` ### 安裝 Hexo ``` npm install -g hexo-cli ``` ### 初始化 Hexo 安裝完 Hexo 後,執行下方指令,Hexo 就會在指定資料夾 <folder name> 中新建所需要的的檔案。 ```cmd hexo init <folder name> cd <folder name> npm install //安裝 git 部署套件 npm install hexo-deployer-git --save ``` ### 啟動 Hexo ``` 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 行 ```yml # Site title: subtitle: '' // 內容描述(給搜尋引擎看的) description: '' keywords: author: language: en timezone: '' ``` ### 將 Hexo 配置到 GitHub ``` url: https://<username>.github.io/ deploy: type: git repo: https://github.com/<username>/<username></username>.github.io.git branch: master ``` - 若沒有 GitHub 帳號 1. 至 [GitHub](https://github.com/) 申請 2. 新建 Repositories 取名為 <blogname></yourname.github.io>.github.io ### 更換主題 可至 [Themes](https://hexo.io/themes/) 挑選,據說最多人用的是 [NexT](https://theme-next.org/) - 安裝 NexT ``` git clone https://github.com/theme-next/hexo-theme-next.git themes/next ``` - 修改 _config.yml ``` theme: next ( default landscape ) ``` - 重新啟動 server ``` hexo server ``` ### 新增文章 ( 待研究 ) 文章會以 Markdown 格式來撰寫,並且檔案存放在 <folder name>/source/_posts/ ``` hexo new "<title>" ``` ###### tags: `GitHub`, `Hexo`, `GitHub pages`, `Blog`