I used to use blogging platforms for years and I realized that I used a very few of built-in features. I received a lot of spams in comments that I have to moderate (even with anti-spam plugins). Anyway there are many positive things, they helped me a lot to save time and to push content fast with very user-friendly interfaces. That was my own experience as a user.
So, I decided that I had to make a blog manager that exactly fits my needs:
- Very low moderation
- Display pages very fast
- Template system
Therefore, I have published a new project on GitHub some months ago, calls: blgn. This is a very basic blog generator in Node.js. You can find the whole source code here. Some HTML skills and a little bit of programmation skills are required to handle this tool if you want to create new templates.
- blgn architecture
- Output static files for performance
- Next steps
Like most of template engines, the structure of blgn is composed with a parser, a tokenizer, an interpreter and especially, a minifier. The particularity is that all user contents are stored in Markdown files in
pages folders. Roles of each part are explained below.
Template files can be separated into several files, and each file can be included in another to avoid duplicate code. It also uses metadata inside user content files to indicate associated tags/category, the post's or the page's title and date of publication.
Parser and tokenizer
As its name tells, the parser gets templates files and it finds all specific instructions of blgn which starts with
%. While I am writing this post, the regular expression of instructions is:
The first part is dedicated for an instruction like:
include path/to/file or
foreach list another_instruction.
All known instructions are treated by the system as tokens:
FOREACH_TK. Then, blgn negotiates commands such as displaying a variable content or a string, including another file and making operations recursively.
All template files are located in
template/ folder. A template contains HTML mixed with blgn instructions. Here is an example of a page that includes other sub-parts:
<!DOCTYPE html> <html> %include modules/head.tpl% <body> <div id="global"> %include modules/header.tpl% <div class="content"> <div class="content-middle"> <ul> %foreach currentPage.tags include modules/tag_item.tpl% </ul> <article id="article"> %print currentPage.source.html% </article> </div> </div> %include modules/footer.tpl% </div> <!-- script --> %include modules/script.tpl% </body> </html>
User content and metadata
Every user content files are written with Markdown, I mean pages and posts. As blgn aims technical bloggers, that is a wise choice because the structured language is widely used in the developing world. Moreover, it is a pretty user-friendly syntax and HTML could be mixed with it. That is to say, user content files also accept pure HTML. Note that GitHub and Jekyll are using Markdown too. By the way, a lot of resources and tools can be found in GitHub and on the Internet.
Posts and pages have specific metadata on top of each Markdown file. Metadata is written in an HTML comment. This information is used to associate tags, category, date and title of pages and posts. An example below:
This is an exhaustive list. Of course, new items can be added and extracted by blgn.
Output static files for performance
A fact that no one can contest: less we do operations, faster is the rendering. This is one of what I am aiming with blgn. No server operations are required to output HTML like PHP, Python or Ruby but a Web server like Apache, Nginx, etc.
<div class="a q D j K"> <span id="e">text</span> </div>
Many improvements need to be done. blgn has to reach a maturity to be suggested as a real alternative of CMS.
- Improvements in templates: support conditional instruction, complex loop.
- Make the implementation of a theme (templates) easier.
- Make blgn a Node Package Module.
- Build a standalone server for quick tests when developing.
- Add a feature to deploy files on FTP.
To wrap things up, blgn needs to be comfortable to use for technical bloggers. If someone is interested to develop that open source project, feel free to make pull requests. :)