Over the past few years I have become a massive fan of serverless computing. After being introduced to the concept, it has now become my defacto recommendation to clients. So after deciding to start this blog my initial thoughts where - could I adapt a severless solution? Some initial digging and I came across this post on current options for a serverless blog.
First up, install the hexo-cli globally
npm install -g hexo-cli
Next use the hexo-cli to create your new blog - replacing <folder> with your desired location. More information can be found at the excellent Hexo docs
$ hexo init <folder>
Now you should have everything needed to start creating your blog content. Hexo comes with a built in server mode however in order to replicate being served from S3 and ensure the static site works as expected, install http-server.
npm install http-server --save
Paste the following helpful scripts into your
Open two tabs of your command prompt:
- in the first tab run
npm run watch- this will watch the hexo file directory and generate static files into the public folder
- in the second tab run
npm run start- this will use http-server to serve the geneated public folder on port 8080
You should now be able to see your blog in your favourite browser at
git clone https://github.com/klugjo/hexo-theme-clean-blog.git themes/clean-blog
_config.yml theme property to use the newly downloaded theme.
Lastly update the <AWS_ID>, <AWS_SECRET> and <BUCKET_NAME> in the deploy npm script to the relevant AWS details and then run
npm run deploy
to copy the public folder to your S3 bucket.
If you want to connect you S3 bucket to your Route53 domain then please follow this article, this article also includes details on how to turn your bucket into a static file host.
Congrats - you now have a serverless blog :)