Skip to content

ferd/blog3r

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

blog3r

A rebar plugin attempting to re-make https://github.com/ferd/blogerl but as a rebar3 plugin for a custom compiler module so that it can reuse the DAG code and do partial blog re-builds without having to handle the tracking itself.

This is still experimental code and I wouldn't expect anyone to use it at this point.

Structure

The plugin expects to work on the following project structure:

./
├─rebar.config
├─src/
│ └─ some.app.src
├─templates/
│ ├─ index.tpl
│ ├─ rss.tpl
│ ├─ base.tpl
│ └─ ...
├─posts/
│ ├─ post1.tpl
│ ├─ post2.tpl
│ ├─ post3.tpl
│ └─ ...
└─compiled/
  ├─ index.html
  ├─ feed.rss
  ├─ post1-generated-slug.html
  ├─ post2-generated-slug.html
  ├─ post3-generated-slug.html
  └─ ...
  • A rebar.config configuration file
  • The src/ directory is required strictly for the project to be picked up by rebar3. If you do want to write code snippets and test them to only later import them into the blog, that can be a decent place to do it.
  • The templates/ directory contains basic Django templates and is used as the doc_root (default lookup path) for all inclusions for paths. Only files with the .tpl extension are picked up.
  • The posts/ directory is configurable, and should contain only specific blog posts' template files. Only files with the .tpl extension are picked up.
  • The compiled/ directory is where the plugin currently puts all the rendered posts, at the top level.
  • A _build directory will always be generated by rebar3 even though you may not need it.

There is also an assumed dependency on pygments being installed for code highlighting to be done entirely offline. Code declared with <pre class="erlang">...</pre> will get erlang syntax highlight, for example. Warnings will be output if pygments isn't available.

Configuration

Add the plugin to your rebar config, and configure the blogs and blog posts:

{project_plugins, [
    {blog3r, {git, "https://github.com/ferd/blog3r.git", {branch, "main"}}}
]}.

{blog3r, [
    %% Variables that are defined in all templates
    {vars, [
        {url, [{base, "https://example.org/"},
               {img, "https://example.org/static/img/"},
               {js, "https://example.org/static/js/"},
               {css, "https://example.org/static/css/"},
               {erl, "https://example.org/static/erl/"}]}
    ]},

    {sections, #{
      %% List of all the posts by date, title, and name of the post template
      %% (entries sorted by newest to oldest)
      %%       <source>  <output subdirectory>
      main => {"posts/", "/", [
          %% Datetime in RFC 2822 format,  Title of the post,  Source file
          {"Tue, 20 Oct 2020 10:00:00 EDT", "Markdown Test", "markdown.tpl"},
          {"Wed, 14 Jul 2010 00:00:00 EST", "Second article", "second.tpl"},
          {"Tue, 13 Jul 2010 00:00:00 EDT", "Hello, World", "hello.tpl"}
      ]}
    }},

    %% Define an index of all blog post entries
    {index, #{
        %% Name of the index file itself
        template => "index.tpl",
        section => main,
        out => "index.html"
    }},

    %% How to generate the RSS Feed. A template should have it
    %% already set in the project structure.
    {index, #{
        template => "rss.tpl",
        section => main,
        out => "feed.rss"
    }}
]}.

%% Additional hooks if you want to move static files to the output directory
%% after each build.
{pre_hooks, [
    {compile, "mkdir -p compiled/static"}
]}.
{post_hooks, [
    {compile, "cp -r static/* compiled/static/"}
]}.

Plugin Template

If you declare the plugin globally (in ~/.config/rebar3/rebar.config), templates for blog projects will be available, setting up a basic structure:

$ rebar3 new blog testblog
===> Writing testblog/rebar.config
===> Writing testblog/templates/base.tpl
...
===> Writing testblog/src/testblog.app.src
$ cd testblog
$ rebar3 compile
...
===> Analyzing applications...
===> Compiling testblog

The files will be built in ./compiled/. Edit rebar.config to set the proper hostnames and paths since by default, absolute links at https://example.org are used. Absolute links are preferred for all link configurations since otherwise, RSS entries containing images will link to the reader app's path and not the original site.

About

A small static blog engine written as an Erlang compiler plugin

Resources

License

Stars

Watchers

Forks

Packages

No packages published