托管服务Hexo博客Start blogging with Hexo (Part 1)
eugewxBeen feel like to start the personal blogging for sometimes, but due to project rushing. Now finally get some free time to breath.
1. Prerequisite
- Node.js (Should be at least Node.js 10.13, recommends 12.0 or higher) Download here
- Git Download here
- Domain Name (Bought in few years back)
- GitHub Account
2.Install Hexo
- Once all requirements are installed, you may install Hexo with npm
- Verify Hexo installed with
hexo -v
3.Setup Repo in Github
- Go to Github and setup a Repository named in
<username>.github.io (Repo must match with github username)
- Set the repo as public
- Enable README file
- Create Repository
4.Setup SSH Keys
- Open GitBash
- Config username and email
1 2
| git config --global user.name "username" git config --global user.email "email"
|
- Validate it with
git config -l
- Generate SSH Public key
1
| ssh-keygen -t rsa -C "email"
|
- Find the public key file
id_rsa.pub from C:\Users<user>.ssh path
- Use
Notepad or VSCode to access the .pub file and copy the content
- Go to GitHub, top right profile icon select
settings > SSH and GPG keys, and Add new SSH key.
- Verify SSH key working
You should able to see Hi ! You’ve successfully authenticated, but GitHub does not provide shell access. Now, we had completed the environment setup
5.Initial Hexo Project
- Setup blogging path (Where my path is stored inside NAS Z:/blog)
- Go to
hexo-blog, and proceed with npm i
- After initial, we will get below structure
- node_modules : dependencies
- scaffolds : Template for blog
- source : Folder to store blog markdown
- themes : Themes
- .npmignore : Ignore the blog markdown when publish
- _config.landscape.yml : Theme configuration file
- config.yml : Hexo configuration file
- package.json : Misc information including Project Name, Desc, Version, Developer etc.
- Start the hexo with
hexo server or hexo s
- Access to
http://localhost:4000 with browser to check if the hexo blog had successful running locally.
6.Push Static Blog to GitHub Pages
- Install hexo-deployer-git
1
| npm install hexo-deployer-git --save
|
- Edit
_config.yml based on the your preferences. Official reference
1 2 3 4 5 6 7 8
| title: <Site title> subtitle: '' description: '' keywords: author: <author username> language: en timezone: 'Asia/Singapore'
|
- On the last line of
_config.yml change the deploy config by following
1 2 3 4
| deploy: type: git repository: git@github.com:eugeneewe/eugeneewe.github.io.git branch: main
|
- After complete config, execute the below command to deploy it into GitHub repo
1
| hexo clean && hexo generate && hexo deploy
|
- hexo clean : Remove previous generated static file
- hexo generate : Generate static file, can use
hexo g in shortcut
- hexo deploy : Deploy static file, can use
hexo d in shortcut
- Wait for couple minute and access https://eugeneewe.github.io with browser to check our Hexo blog is online!
🔗 References
- Hexo Official Guide
- Hexo博客搭建基础教程(一)