Skip to content

Instantly share code, notes, and snippets.

@clarete
Created July 24, 2020 13:29
Show Gist options
  • Save clarete/38dbd1594c3a5f82e00a84efa11f1878 to your computer and use it in GitHub Desktop.
Save clarete/38dbd1594c3a5f82e00a84efa11f1878 to your computer and use it in GitHub Desktop.

Goal

Tool for easily generating HTML assembled from a template off of org mode files

One API

The function `blorg-gen` takes a pattern that matches file names and apply a template to generate one HTML for each Org file yielded by the search.

Templating

All file tags should be available as attributes from the `post` variable.

;; publish.el goes in the root of the blog
(unless (package-installed-p 'blorg)
(package-install 'blorg))
(require 'blorg)
;; Generate the blog posts
(blorg-gen
:input-pattern "src/.*\\.org$"
:input-exclude (regex-opt "index.org" "blog-index.org")
:input-filter 'blorg-filter-published
:template "theme/post.html"
:output "blog/{{ slug }}.html")
(blorg-gen
:input-pattern "sources/.*\\.org$"
:input-exclude (regex-opt "index.org" "blog-index.org")
:input-filter 'blorg-filter-tags
:template "theme/category.html"
:output "blog/{{ category }}/index.html")
;; Generate the index of the blog (will have access to the list of posts)
(blorg-gen
:input-pattern "sources/blog-index.org$"
:template "theme/blog-index.html"
:output "blog/index.html")
;; Generate index of the entire site
(blorg-gen
:input-pattern "sources/index.org$"
:template "theme/index.html"
:output "index.html)
{# blog-index.html --- Blog Home template
Generates the index page of the blog. List of posts is passed as the
variable `posts` and each `post` contains its metadata and content.
#}
{% extends "layout.html" %}
{% block body %}
<h1>Posts</h1>
<ul>
{% for post in posts %}
<li><a href="{{ post.url }}">{{ post.date|fmt("YYYY-MM-DD") }} &mdash; {{ post.title }}</a></li>
{% endfor %}
</ul>
{% endblock %}
{# layout.html --- Base template inherited in all the other templates
The blocks available in this file are:
* title: What will show within the HTML <title> tag.
* nav: Navigation bar with Links, a default is provided
* body: Main content which starts empty
* footer: Bottom links, default is provided
#}
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>{% block title %}home{% block %}</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="nav">
{% block nav %}{% endblock %}
</div>
<div class="body">
{% block body %}{% endblock %}
</div>
<div class="footer">
{% block footer %}{% endblock %}
</div>
</body>
</html>
{# post.html --- Blog Post template ; -*- Mode: Web; -*-
This template is executed once for each post published. Metadata and
content are available in the `post` variable, passed by the executor.
#}
{% extends "layout.html" %}
{% block body %}
{# Access to the post's metadata #}
<div class="title">
<h1>{{ post.title }}</h1>
<span class="pubdate">{{ post.date }}</span>
</div>
{# Access to the content #}
<div class="content">
{{ post.html_content|safe_html }}
</div>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment