# blogc [![Build Status](https://semaphoreci.com/api/v1/projects/bd67545c-8593-4a37-ba94-ef1187a6d58d/402577/badge.svg)](https://semaphoreci.com/rafaelmartins/blogc) A blog compiler. ## Design Notes The main idea is simple: a source file is read by the compiler, and a result file is written by the compiler. The source file must provide (almost) all the data needed to build the result file, including any variables. The result file is built using a template, that defines how the information provided by the source file should be used to generate a reasonable result file. The compiler will always generate a single file, no matter how many source files are provided. If more than one source file is provided, the compiler (and the template) must know how to convert them to a single result file. The templates can define blocks. These are the block rules: - If something is defined outside of blocks, its raw content should be always included. - If something is defined inside a block, it should only be included if the block matches the compiler argument expectations, e.g.: - ``entry`` should be include if just one source file is provided. - ``listing`` should be included if more than one source file is provided, being included once for each source file, if the compiler is called with ``-l``. - ``listing_once`` should be inclueded if more than one source file is provided, but only once, if the compiler is called with ``-l``. - Template blocks can be defined multiple times in the same template, but can't be nested. The variables defined in source files are only available inside of blocks. The variables defined in the command line are global and available everywhere. Inside blocks, variables defined in source files are always used, even if a global variable with the same name exists. The templates can use conditional statements: ``{% if VARIABLE %}`` or ``{% if not VARIABLE %}``, and ``{% endif %}``. They check if a variable is defined or not. Variables defined in source files are not available in ``listing_once`` blocks, because it is not possible to guess which source file would provide the variable contents. Global variables, defined in the command line are available. As the compiler is output-agnostic, Atom feeds and sitemaps should be generated using templates as well. The compiler won't touch the content. If the user write pre-formatted text it will stay pre-formatted, and the user may want to enclose the ``{{ CONTENT }}`` statement with ``
`` and ``
`` tags in the templates. For more flexibility, the user can even write raw HTML in the source content. The compiler is designed to be easily used with any POSIX-compatible implementation of ``make``. ### Source file syntax ``` TITLE: My nice post DATE: 2007-04-05 12:30:00 ---- test content. more test content. ``` If more than one source file is provided to the compiler with the ``-t`` argument, they won't be sorted, and will be included by ``listing`` blocks in the order that they were provided in the command line. Variables are single-line, and all the whitespace characters, including tabs, before the leading non-whitespace character and after the trailing non-whitespace character will be removed. Raw content is available in template blocks as the ``CONTENT`` variable. ### Template file syntax ```html {% block entry %} My cool blog >> {{ TITLE }} {% endblock %} {% block listing_once %} My cool blog - Main page {% endblock %}

My cool blog

{% block entry %}

{{ TITLE }}

{% if DATE %}

Published in: {{ DATE }}

{% endif %}
{{ CONTENT }}
{% endblock %} {% block listing_once %}{% endblock %} ``` This template would generate a list of posts, if multiple source files were provided with ``-t``, and single pages for each post, if only one source file was provided. The ``FILENAME`` variable is generated by the compiler, and is the source file base name without its last extension. ## Roadmap The first release will happen as soon as ``blogc`` can build its own website (http://blogc.org/). ;-)