Setup a Hexo Blog
This is the first post of this blog, and I will write about how to set up a blog using Hexo.
Setup
Requirements:
- Node.js
- git
Install Hexo
1 | npm install -g hexo-cli |
-g
flag will install Hexo and is dependencies globally, which is not recommended but is the easier way to do.
If you install the modules locally, you need to setup your $PATH to find your nodejs binaries.
I use this function function npm-do { (PATH=$(npm bin):$PATH; eval $@;) }
. And you can run commands like npm-do hexo server
.
Setup Hexo
On a empty folder:1
hexo init
To install a theme, like the one I am using on this blog:1
git clone https://github.com/probberechts/cactus-dark.git themes/cactus-dark
You should have something like this in your blog directory.
1 | ➜ blog $ ls |
Change the theme property in the config.yml file. The newly installed theme also has a config.yml file, you have to edit the one located at the root of your blog.
1 | # theme: landscape |
Run
You can run a local server to preview how your blog look,1
hexo server
When the server is running, Hexo will watch for file changes and update automatically so it’s not necessary to manually restart the server.
Deploy
You will need to install hexo-deployer-git
to use the git deployer.
1 | npm install hexo-deployer-git --save |
At the end of your config.yml file configure:
1 | deploy: |
For example:
1 | deploy: |
And then you can run a deploy with:
1 | hexo deploy |
This will create a directory called public
and generate all the assets and html files needed to publish your site. Also will create a git repository in a directory named .deploy_git
and copy all the files from public
.
You will be asked for your GitHub user and password since it will try to push the commit via https.
Version control
If you want to keep track of your changes on the source files that generate your blog. You can init a git repository on the root of your blog directory.
Writing
Adding a new post1
hexo new {postname}
Your new post will be located at source/_posts/{postname}.md
and you can edit it with your favorite editor, using the GitHub Markdown Syntax.
To deploy the new post, simply run: hexo generate -d
This will compile all the new assets on the public
directory and upload it to GitHub.