Build your personal website with github & hexo

This is about the basic steps of building your own website with only a github account as prerequisite.
Start building your knowledgebase!!!
Set up your computer
- Installation
- node.js and npm: NodeJS is a cross-platform Javascript runtime environment; npm allows open-source web developers to share and borrow packages for app development.
(Here you can find more explaination of them: https://radixweb.com/blog/installing-npm-and-nodejs-on-windows-and-mac) - git: to manipulate the deployment on github.
- hexo: an easy and convenient blog workflow.
1
npm install hexo
- Sign up github account and create new repository
- Go to https://github.com to create a new account if you don’t have one, set a nice user name which will be part of your website address.
- Create a new repository named as username.github.io, where all the code for your website will be stored at.
(The address of your future website will be http://username.github.io.)
- Configure the computer
- Connect the device with github repository
In git bash terminal, execute following command:Reminder No such file or directory means you haven’t used git before and you need to create the ssh key with the following command:1
cd ~/.ssh ## check the existed ssh key in your local computer if there is one
Then a file ~/.ssh/id_rsa.pub will be created and the ssh key is the cotent in it.1
ssh-keygen -t rsa -C "your-email-address"
You just need to copy and paste all the content in that file into github, the connection will be done. This is where to paste in github:
Go to account setting -> SSH and GPG keys -> New SSH key
*Note*: Title is the name you give to your connected device; Key area is where you paste the ssh key.
Then, go to your local device, and run:
The message `Hi username! You've successfully authenticated, but GitHub does not provide shell access.` means you've done it successfully. Next, two more commands need to be run:1
ssh -T git@github.com
And this is finally done.1
2git config --global user.name "user-name" ## your github user name
git config --global user.email "xxx@xx.com" ## your github signed up email - Create a folder in your local computer
Create a folder in your computer where everything about the website will be stored at, as an example here: ~/blog - Hexo initiation
Go into the folder you just created for your website (~/blog), and implement the initiating command:Then some files and folder about hexo will be created.1
hexo init
- Set up the _config.yml file
To let your computer know it’s connected to the github, following settings must be done in file ~/blog/_config.yml:1
2
3
4deploy:
type: git
repo: git@github.com:user-name/user-name.github.io.git ## substitue with your own user name
branch: master
- Connect the device with github repository
Post an article using basic commands
- Create a new articleThis command will create a new file new-post-name.md in folder ~/blog/source/_post, which is the content of your new post.
1
hexo new "new-post-name"
- Edit the article
Choose any Markdown editors you like to put your content in.
Some tricks to make your post looks more pretty:- Using
<!--more-->to only show the content before it in the home page - Using html grammer to set the format of images:
<div style="text-align:center"><img src="./sample.png" width=500 height=350 /></div> - Change the color of certain sentence with
<font size=5 color="#FF0000">This is the example.</font> - Change the position of sentence with
<center>This is the example.</center>
- Using
- Upload the articleWell, so far, you can already read your article in http://user-name.github.io
1
2
3hexo generate (hexo g) ## Generate static files in public folder
hexo server (hexo s) ## To preview your new article at address: http://localhost:4000
hexo deploy (hexo d) ## To deploy your new article
Decorate your website
Not necessarily needed, but will make your website more personalized and pretty.
- Theme
Change the theme of your website to any kind in the repository: https://hexo.io/themes/ - Add tags
1
hexo new page tags