Build Blog with Hexo and Github Page
Powered by Hexo, deploied with Github Page. I first build and test on Github Codespace, but no long after, I run out of my 120 free hour. Thus I shift to my 256G M1 Mac( ̄◇ ̄;). And there are some problems with codespace, which I will explain after.
Steps
- Prepare Git, make sure you can pull and push.
- Install Node.js.
- Set up
${username}.github.io
Repository, make it public. - Install hexo.
- Find your favourite Theme and follow the document to set up your blog. You can first test your website locally.
- Depoly your Blog to with Github Page
Git
As my blog is hosted on github, I believe anyone who have access to this website is familiar with git. Anyway, there are plenty of source address your problems with git. RTFM, STFW, :)
Install Node.js
Refer to the guide provided by Node.js.
I first setup my blog on codespace, where Node.js is preinstalled with older version.
Then I installed Node.js on my M1 Mac with commands below: (try to install nvm with brew install nvm
will run into problems so I don’t recommend it)
Using Homebrew:
1 | brew install node |
Don’t know why, mirror site for node.js returned error: 404, it took some time to downloads from default domain. I first the node version on website is node-19.3.0, but brew kept trying to downloads node-19.2.0, in the end, I down node@18.
After downloads, test with:
1 | node -v |
Setup ${username}.github.io
Follow the guide, but don’t need to make your own index.html
Install hexo
First make a new empty directory. If you want to put it to git repo, first pull the repo, and add a new empty directory.
1 | npm install -g hexo-cli |
then test your website locally
1 | hexo s |
It’s now with the default theme and content, we will edit it in next step.
Before, we went next step, let’s first deploy it with Github Page.
In _config.yml
, set up:
1 | timezone: 'Aisa/Shanghai' |
After save, install package for deploy
1 | npm install hexo-deployer-git --save |
Before deploy, make sure your Github Page, and git push using ssh are both setup. Went to your hexo site repository and deploy with:
1 | hexo clean && hexo d -g |
Then access your website from ${username}.github.io, you can first access your github repository to see if it has been build successfully.
Problems of build your blog with codespace
The point is that it seems your can’t pull and push to another repository from codespace opened for one repository. Which means you can’t put your hexo-site
at codespace to deploy it to Github Page. To fix this problem, I first tried to put it under the ${username}.github.io, but then Github Page build failed when it read _config.yml
for hexo. Then I have to add the hexo-site directory to .gitignore
. And no long after, I nearly reach the end of my 120 free hour. In the end, I switch to my M1 Mac.
Make Blog the Way You Like
I picked the Theme redefine, choice your own theme and config it.
Install theme
1 | npm install hexo-theme-redefine@latest |
change theme in _config.yml
1 | theme: redefine |
setup theme config file
1 | touch _config.redefine.yml |
please remember that social_contact is only available for brand.
word_count
1 | npm install hexo-wordcount |
local_search
1 | npm install hexo-generator-searchdb |
in _config.redefine.yml
add:
1 | # Search |
comment
Not yet set.
Math
1 | npm install hexo-filter-mathjax |
in _config.yml
add:
1 | mathjax: |
Compress
1 | npm install hexo-all-minifier |
I met unfixable venerablity after install this. Don’t recommend install.
Bug
Some error Happen
It’s fun when I test locally:
But error happened after I deployed it on Github Page
Further Learing
Please refer to Hexo
- Post title:Build Blog with Hexo and Github Page
- Post author:Meqt
- Create time:2022-12-17 14:48:51
- Post link:https://meqtmac.github.io/2022/12/17/Build-my-Blog/
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.