Carlos Fenollosa — Blog

Thoughts on science and tips for researchers who use computers

Creating a simple blog system with a 500-line bash script

September 20, 2011 — Carlos Fenollosa

Update: the script is now at a github repo!

One of the drawbacks of data analysis is that sometimes there is a task that blocks you and you need to wait for a couple of days to continue working on that project. Yes, there are more projects, and there's always papers to read, but it's fun to start small projects that can be finished in an afternoon—let me clarify: a long afternoon.

So here it is, BashBlog v1.0, a Bash script that handles blog posting. It features:

  • Simple editing of the posts with your favorite text editor
  • Transformation of every post to its own html page, using the title as the URL
  • Generation of an index.html file with the latest 10 posts
  • Generation of an RSS file! Blog's magic is the RSS file, isn't it...?
  • Generation of a page with all posts, to solve the index.html pagination problem
  • Rebuilding the index files without the need to create a new entry
  • Google Analytics support
  • Auto-generated CSS support
  • Headers, footers, and in general everything that a well-structured html file has
  • xhtml validation, CSS validation, RSS validation by the w3c
  • Everything contained in a single 500-line bash script!
  • A simple but nice and readable design, with nothing but the blog posts

What doesn't it support? Of course, comments. Comments would greatly increase the code complexity, would require a strong antispam system to avoid flooding and might pose a security issue on the server. So sorry, but no comments, at least until I have another free afternoon waiting for some computations to finish.

I wanted to post something to celebrate the grand opening, and what's better than a meta post explaining the script that generates this blog?

In the future I'll post some scientific tips or tutorials which don't really fit on the home page and maybe some rants about my work. To end up, if you are interested in bioinformatics or general science computing, check the unix section of my home page for more tips, tutorials, FAQs and cheat sheets.

I won't post with any periodicity, so you can always subscribe to the RSS feed to get the updates delivered to you when they're generated.

Hope to have you around sometime!

Edit: If you use the script for your own blog, please send me an email with your suggestions or drop me a comment on Twitter! It will be much appreciated and, until comments are implemented, the only way to provide feedback

Tags: bashblog

Comments? Tweet