In this post I'll discuss the process i went through to setup my first blog in hexo. Also I'll suggest some helpful stuff to automate compilation of css and template changes without having to exit and run hexo serve everytime.
Necessary links to get started:
NVM is the preferred method to install nodejs. Although nvm is not available for Windows there is an alternative called nvm-windows which can be used to install mulitple versions of nodejs.
1nvm list #fetch the available versions2nvm install <version> # install the required version3npm install -g hexo-cli #installs hexo
1Note: -g so that we can install the cli globally and access it in the shell
hexo init
cmd in that directory.themes
directory.hexo serve
.localhost:4000
to check if everything runs fine.Now that the required base setup is done we can now install the theme. Every theme has its own installation guidelines so checkout your themes respective readme/wiki sections.
hexo-render-pug
. Install this to ensure html will be generated.1npm install hexo-render-pug
anatole
or any other name you prefer.landscape
which can be changed in the _config.yml
in the root directory._config.yml
and set the theme entry to anatole
.1theme: anatole
hexo serve
the new theme will be loaded. Refresh if already open.Changes to the existing theme
Minor changes have been made to the theme as follow
p
tag.en
in anatole/layout/layout.pug
else it will be set to zh-CN.anatole/layout/partial/nav.pug
hexo serve
doesnt pick up the changes to files made during development. In order to get the latest changes to the blog one has to quit the current running instance of hexo serve and run it again. This can be annoying but there is a way to avoid this.
Note: This doesnt merge the changes made to the _config.yml
.
Install node-sass to compile scss to css
First install node-sass to compile the changes from scss and generate a css file. All the changes to the css has to be made in styles.scss file. To compile the scss file to css run. To automate this for file changes we can add watch option -w.
1# install2npm install -g node-sass34# compile5node-sass ./style.scss ./style.css67#compile with watch8node-sass -w ./style.scss ./style.css
Serve files without having to restart “hexo serve”
Now to serve the files without using hexo serve
. This method requires first to generate the blog files using hexo generate -w
, here option -w watches the file changes, which pushes generated blog files to public
folder in the root directory and lastly serving this folder via http server.
Use the npm package http-server
to serve the generated blog.
1#install2npm install -g http-server34#Serve generated blog5http-server ./public
So a total of three instances of shell has to be run for each of the above commands to make this work.
The layout is created using template engine pug
. To make any changes to the layout modify the themes layout files.
Now that the basic setup is done we can continue writing blog posts using the Markup Language.
Checkout the documentation for Hexo to customize the theme furthur to your liking.