Tina Tang's Blog

在哪裡跌倒了,就在哪裡躺下來

0%

Hexo筆記(1)-Hexo基本指令

學習關於 Hexo 的基本指令,包括建立專案、新文章、新增 menu、跑 server 和 deploy 等等


建立一個Hexo專案

1
2
$ hexo init 專案名稱
$ hexo init blog

新增menu

(about/tags/categories…)

1
2
3
$ hexo new page about
$ hexo new page tags
$ hexo new page categories

執行完成後source資料夾底下會出現對應資料夾和其底下的index.md

建立新文章

1
$ hexo new "我的第一篇文章"

執行完成後source/_posts資料夾底下會出現我的第一篇文章.md

跑server

1
$ hexo server

修改_config.yml的deploy設定

1
2
3
4
deploy
type: git
repository: git@github.com:你的帳號/你的帳號.github.io.git #你的github倉庫
branch: main #分支

repository: 到你的github倉庫點選Code -> copy按鈕,即可複製完成
Imgur

產生靜態檔案

1
$ hexo generate

安裝hexo-deployer-git

(第一次deploy前執行即可)

1
$ npm install --save hexo-deployer-git

部署到遠端

1
$ hexo deploy

一鍵部屬

  1. 安裝 hexo-deployer-git
  2. 清空 _config.yml 的現有資料,並新增以下組態:
1
2
3
4
5
deploy:
type: git
repo: https://github.com/<username>/<project>
# example, https://github.com/hexojs/hexojs.github.io
branch: gh-pages
  1. 執行 hexo clean && hexo deploy
  2. 瀏覽 <GitHub 用戶名>.github.io 檢查你的網站能否運作。