Hexo + Github: Build your personal blog 建立一个属于你的部落格
What is Hexo? 什么是 Hexo?
Hexo is a blog framework that can generate static websites. Compared to dynamic websites, a database is needed. The files of static websites are stored on the computer, which will be more convenient for transfer in the future.
Hexo 是一個能夠產生靜態網站的網誌框架,相對於動態網站需要有一個資料庫,靜態網站的檔案存在電腦上,將來在轉移的時候也比較方便。你也能够将你的部落格发布在 Github-Pages 上,无需任何费用。
不会编程的也没有关系哦,只要是 Windows 使用者照着以下方法一切都能在 CMD 搞定
Setting Up Envinroment
Getting Ready
Make sure that you have installed Nodejs and Git before proceed to the next step.
If you are using Windows
- CMD
- Nodejs
- Git
Install Hexo
Install Hexo in the terminal with npm.
1 | $ npm install -g hexo-cli |
Make sure that Hexo is installed in your system
Hexo would not work if it is not installed.
如果 Hexo 没有安装成功, 它将不会运行。
1 | $ hexo -v |
Create a project
1 | $ hexo init blog #Initiates a blog 建立部落格 |
Run a test
Test the server to see whether it could work successfully.
试跑下服务器
1 | $ hexo server |
How to create new post?
Create a post
这里我们简单的开一个新的文章,文章名称可以随意设定。在这里我们就命名为 first-post。
1 | $ hexo new first-post |
Edit post
Windows 使用者请到 C:\Users\ 这里是你电脑的名字 \blog\source_posts 打开你刚刚开的 post 的名字 first-post.md。
打开了之后你会看到一下的信息,在这些信息的下面可以写下你的信息。
1 | --- |
因为是 markdown language 这里推荐几款软件
Online Editor 无需下载
Download Editor 需要下载
不熟悉 markdown 的
Markdown Guide
Load server
使用 hexo server 啟動本地伺服器,來預覽 Hexo 部落格,預設開的 port 為 4000,不過像是下圖,如果 Port 被占用,就無法正常運行。
1 | $ hexo server |
在瀏覽器輸入: localhost:4000 就可以看到我們建立好的 Hexo 部落格囉。
Create a github account
Create a repository
登陸 Github 帳號並新增一個 repository ,”Repository name” 命名規則為 “用戶名”+”.github.io”。
進到視窗畫面後依序輸入以下 3 行指令來獲取密鑰文件。
1 | $ git config --global user.name "github 用戶名" |
Take key
進到剛剛產生的密鑰位置,預設位置為”C:\Users\用戶名.ssh”,找到 “id_rsa.pub” 並使用文字文件打開,將所有內容複製起來,待會使用。
Setup key
回到 Github “Setting” 中的 “SSH and GPG keys”,新增一個 SSH keys,”Title” 名稱可以任取,”key” 就填入剛剛複製的密鑰。
Set information to use Git
Install Hexo deployer git in the terminal
1 | $ npm install hexo-deployer-git --save |
Open _config.yml file in C:\Users\ username \blog
更改 C:\Users\ username \blog_config.yml 里面的信息
1 | deploy: |
生成靜態檔案
1 | $ hexo generate --watch |
Deploy your blog 发布
將網站部署到 Github Pages 上
1 | $ hexo clean |
Summary 总结
Hexo is a great environment to post your blog.
Reference 参考资料
Remarks 备注
Create new a new page or post 新增页面或文章
1 | $ hexo new [layout] !title! |
layout 布局
有三种布局个别是 post, page 和 draft
Layout | Draft |
---|---|
post | source/_posts |
page | source |
draft | source/_drafts |
Configurations 设定
Basic Settings 基本设置
1 | title: 網站標題 |
Frequent used commands 常用指令
1 | $ hexo generate #產生靜態檔案 |