https://github.com/ferd/blog3r
A small static blog engine written as an Erlang compiler plugin
https://github.com/ferd/blog3r
Last synced: about 1 year ago
JSON representation
A small static blog engine written as an Erlang compiler plugin
- Host: GitHub
- URL: https://github.com/ferd/blog3r
- Owner: ferd
- License: apache-2.0
- Created: 2020-11-03T18:10:11.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-28T12:30:14.000Z (over 1 year ago)
- Last Synced: 2025-04-10T04:11:22.231Z (about 1 year ago)
- Language: Erlang
- Homepage:
- Size: 271 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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](https://pygments.org/) being installed for code highlighting to be done entirely offline. Code declared with `
...
` 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:
```erlang
{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)
%%
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.