How to create a modern blog?
using markdown and python

Over past few years I had tried various blogging platforms, say Live journal, wordpress (self hosted as well), tumblr, microsoft sharepoint etc., Everyone of these had only browser based editors. I was looking for simple text file based blogging software. I came across Jekyll. But, instead of learning it, I wondered why don't I create simple one.

Primary Goals

  1. Write blog using Markdown.
  2. Code highlighting.
  3. Responsive UI.
  4. Tagging posts.
  5. List blogs by date.
  6. Share link over social media.

webgen

Initially, I started working with scala play framework. I tried various storage systems from file system to couchbase server. Every option had different pros and cons.

Storage

  1. File system : It is lowest level you can getting in to. It can be easily be part of a git repo.
  2. MySQL : Most of the blogging software including wordpress use this one. Nothing new or special. Required some sort of ORM.
  3. Elastic search : json document store with extensive search capabilities.
  4. Couchbase : Fast RAM cached json document store. Json documents make easy for iterative devlopment.

Solution

I was concerned about the server cost and i wanted to reduce the compute time for serving the blog files. So, decided to go for simple file based solution. Here, both source blog markdown as well as generated websites will be set of files. So, webgen has to generate set of html files from set of markdown files.

Tech stack

  1. Markdown format is the core of this static website generator. Easier to create clean html from simple text styles.
  2. HTML5 + CSS3 + Javascript: Browser can understand only these 3, No escaping right.
  3. Twitter bootstrap + jQuery: Bootstrap is one of the awesome reponsive UI library available out there and jQuery is required for few of its functionalities.
  4. Font-Awesome : Just love the font awesome icons over default one that comes along with bootstrap.
  5. highlight.js : Easily customizable javascript library available for code highlighting.
  6. Python : Moved over to python from jvm langauges, so that i can learn more by using it.
  7. Jinja2 : Really handy html templating library for python. Comparable to one that comes along with django
  8. Python Markdown package is available in python which generates html out of the markdown text.

Now, all the components are in place.

Repo

  1. webgen : It contained all python code required to generate the website.
  2. sakthipriyan.com : It contains 3 components,
    1. Website template - used by the jinja2 and required css/js files.
    2. Markdown - all blog files in markdown.
    3. Config - config files used for generating the website.

Website Generation

Following set files are generated, when webgen is run.

  1. Home page
  2. Blog pages
  3. Tagcloud page
  4. Tags page
  5. Calendar pages

Deployment

Generate the website using the following command.

#python webgen.py [location of the config file]
python webgen.py ../sakthipriyan.com/conf/local.json

Once the blog is generated it can be easily deployed over any static webserver like nginx or apache webserver. I prefer nginx for being thread less web server.

Conclusion

Though webgen is able to generate website from markdown, it is far from perfect. Lot of things has to be done over coming months, so that it can smartly generate the website.

Share

Great!! You read till this point, just go ahead and share this post to your followers, collegues and friends. Thanks!

About Author

Sakthi Priyan H
Passionate Programmer

  • I am passionate about building excellent teams, processes and systems.
  • Primarily I use Java, Scala and Python for building various systems and tools.
  • Building API services, Big data processing and Machine Learning systems in Crayon Data.
  • Also, interested in Golang and building web apps using Javascript ecosystem.
  • I wrote my first program in BASIC in 1998, Passionate about computers since then.