Rodrigo Rosenfeld Rosas
LightBlog: a file-based blog app
When Heroku discontinued the free plan, I decided to host my site elsewhere. It was an old Rails app, and since I moved from Rails to Roda a few years ago for the apps I maintain, I decided to take the opportunity to rewrite the blog in Roda.
While doing so, I thought it could be a good idea to make the bulk of it an open-source project, and that’s how LightBlog was born. This site is powered by LightBlog with a few changes to support multiple languages (namely English and Portuguese) and automatic code-reloading (using my auto_reloader gem), plus a few changes to the default views.
It’s basically a Roda application using the
multi_run plugin to
serve two LightBlog apps, one for the English articles and another one for the Portuguese articles
with a slightly different configurations passed to LightBlog.create_app
.
How it works?
LightBlog (and my previous Rails-based site) is inspired by Toto, a git-powered, minimalist blog engine.
Just like it happens in Toto, articles are written in Markdown and stored directly on disk (usually in a Git repository) and contain some metadata associated to it in the form of a header written in YAML, containing arbitrary information besides the article title and published / updated at dates.
The articles history is basically the git history of the articles repository. When using LightBlog to serve your articles, I’d strongly recommend you to keep your articles in a separate repository.
This approach provides many benefits:
The application is safer
There’s no database, so no risk of SQL injection and other related vulnerabilities. If your blog is attacked by some hacker, the biggest risk would be providing the markdown source of your articles to the attacker. Basically, if you keep a back-up of your articles' repository, you’re safe.
It’s simpler to setup
No need to create and tune any databases.
It’s very flexible / portable
You can easily move from LightBlog to something else in the future if you keep your articles separated from the application. Just create another application that can read your data (your markdown-based article files).
Deploying is easy and the process is very lightweight
LightBlog requires very few resources. This site is hosted in a single e2-micro Compute Engine instance at GCP at no cost at all (it’s within the free tier conditions). The e2-micro engine provides very little CPU and RAM (1GB only) and yet it’s able to serve a blog with LightBlog very easily.
Features
Out-of-the-box, LightBlog provides:
- tagging support: group your articles by tags;
- atom feeds (for all articles and by tag too);
- optional comments provided by Disqus (just provide the Disqus forum/id in the options);
- optional integration with Google Analytics (just provide the GA id in the options);
- optional automatic reloading of the articles;
- a rake task to generate a new empty article;
- a rake task to copy the default views (which can be overridden);
- a
light_blog
command to help you creating a new simple Rack application using LightBlog; - internacionalization/localization support (integration with the i18n gem);
Getting Started
1 | gem install light_blog |
2 | light_blog new myblog |
3 | cd myblog |
4 | bin/rake article:new_article |
5 | # type in the article title |
6 | bin/puma -p 4000 |
Then simply navigate to https://localhost:4000 to view your articles.
Give it a try and let me know in the comments what you think about it.