Use Nem Blockchain to Store Your Hexo Blog

Hexo is a static blog generator which has large amount of handy plugins and themes.
I really enjoyed to write my blog using hexo. However I also have trouble sometimes.

Most of hexo users keep a backup of their blog using git, and however sometimes its forgetable for me to push the contents to remote and when I want to write my blog at another place, I hesitate to do so since I can not render all the blogs I wrote.

When I began to know blockchain technology and nem related development, It seems that you can use the message field of nem transaction to store your blog contents so that you can write your blog at anytime with just a nem transaction with messages of your blog contents.

That’s why I came out with a hexo plugin to fetch your blog contents on nem blockchain. Check Here for more detail.

Basic idea

Nem has provided convenient API for application developers.

When we write our blogs, we launch a transaction using your nem wallet or API, the message field should be your blog contents in markdown format.

When Hexo generate the contents, we first use nem api to fetch the contents from blockchain and save them to local files with the markdown extension. Then those contents get generated and rendered to html just same as your blogs stored on your file system.

One thing to take care is that the message field in nem can support at most 680 bytes of date and with a large message field, you are going to pay more transaction fee.

Usage

This plugin can be configured to use nem mainnet or testnet, Since it’s more easy to get some xem(currency name for nem blockchain), I suggest to use testnet first.

Prepare your testnet account

Use This script to create your testnet private key, public key and address.

You should install nem-sdk first.

Get some testnet XEM

Find a testnet faucet like This one.

Input your account address and get some testnet XEM.

The transaction should be ok in less than 5 minutes.

Create a Hexo blog and Config

Run hexo new your_blog_name to create a new hexo blog.

Go to the blog directory,
run npm install hexo-fetch-nem to install the plugin.

In _config.yaml add the config to use our nem plugin.

1
2
isMainnet: false 
nem_address: your_nem_address

your_nem_address is the nem address you transfer your contents into. You can run the above script again to get an empty account. Don’t mix up your account with XEM inside and the one you are going to write your blog to.

Write your markdown blog and make a transaction

Write down your blog for example like this.

1
2
3
4
### My title

* foo
* bar

and save your blog into a file which can be named for example my_blog.md

Use the following script to launch a tranaction to send the contents of the blog to nem blockchain.

The private key should be the one with XEM inside. You should install nem-ruby first by gem install nem-ruby and then run the script.

1
$ ruby transfer.rb my_blog.md

Generate the blog

Run hexo g to generate the blog and now have a check. Cool. I’s already there.

More

Hexo won’t generate your latest blog unless you run hexo g. To solve the problem, you can have a crontab to run generate repeatedly.

That’s all

I have a demo running. You can have a check. I am ready to write down what I have learned everyday on nem blockchain!