Your own small blog with Jennifer

Jennifer

Markdown posts in, a finished website out: pages, a feed, a calendar and a contact card, built by one small program you can read from top to bottom.

November 2026, by @mplx.
Based on Jennifer 0.26.0

Powered by Jennifer's Cantrip - Markdown into slide decks, https://github.com/jennifer-language/cantrip
1 / 23

What we build

blog/                          public/
  site.toml     title, author    index.html
  events.toml   upcoming events  posts/hello-blog/index.html
  posts/*.md    the posts        feed.xml, atom.xml
  templates/    page layouts     events.ics, author.vcf
  build.j  ->  writes public/    serve.j: preview in a browser
2 / 23

A post is a Markdown file

+++
title = "Tea & templates"
date = 2026-11-09
summary = "How a layout and a page fit together."
+++

A template is HTML with *holes* in it. The program fills
the holes with the title, the date and the text of each post.

File name: posts/2026-11-09-tea-and-templates.md

3 / 23

Splitting front matter from text

func readPost(file as string) {
    def text as string init fs.readString($file);
    if (not strings.startsWith($text, "+++\n")) {
        throw Error{kind: "blog", message: "{$file}: no +++ at the top"};
    }
    def stop as int init strings.indexOf($text, "\n+++\n", 4);
    if ($stop < 0) {
        throw Error{kind: "blog", message: "{$file}: no closing +++"};
    }
    def meta as toml.Value init toml.decode($text[4..$stop]);
    ...
4 / 23

From front matter to a Post

def struct Post {
    slug as string, title as string, date as time.Time,
    summary as string, body as string
};
    ...
    return Post{
        slug: path.stem($file)[11..],
        title: toml.asString($meta, "/title"),
        date: toml.asDatetime($meta, "/date"),
        summary: toml.asString($meta, "/summary"),
        body: markdown.toHtml($text[$stop + 5..])
    };
5 / 23

Markdown becomes HTML

# markdown-demo.j - one Markdown string to HTML
use io;
import "markdown.j" as markdown;

def md as string init "## Why?\n\nA **small** program, *my* rules.\n";
io.printf("%s\n", markdown.toHtml($md));
<h2>Why?</h2><p>A <strong>small</strong> program, <em>my</em> rules.</p>
6 / 23

All posts, newest first

func loadPosts(dir as string) {
    def posts as list of Post init [];
    for (def name in fs.list($dir)) {
        if (path.ext($name) == ".md") {
            $posts[] = readPost(path.join($dir, $name));
        }
    }
    return lists.reverse($posts);
}
7 / 23

A template is HTML with holes

<!doctype html>
<html lang="en">
<head>
<title>{{ .title | html }} - {{ .site.title | html }}</title>
<link rel="alternate" type="application/rss+xml" href="/feed.xml">
</head>
<body>
<header><a href="/">{{ .site.title | html }}</a></header>
<main>{{ block "content" . }}{{ end }}</main>
<footer>{{ .site.author | html }} ... </footer>
</body>
</html>
8 / 23

Pages fill the layout

{{ define "content" }}
{{ range .posts }}
<article>
  <h2><a href="/posts/{{ .slug }}/">{{ .title | html }}</a></h2>
  <p class="date">{{ .date }}</p>
  <p>{{ .summary | html }}</p>
</article>
{{ end }}
{{ .events }}
{{ end }}
9 / 23

Handing data to a template

func renderPage(page as string, data as json.Value) {
    def set as tengine.Set init tengine.newSet();
    def layout as string init fs.readString("templates/layout.tmpl");
    $set = tengine.add($set, "layout", $layout);
    def body as string init fs.readString("templates/" + $page);
    $set = tengine.add($set, "page", $body);
    return tengine.render($set, "layout", $data);
}
    ...
    $data = json.set($data, "/title", $p.title);
    $data = json.set($data, "/post", postData($p));
10 / 23

Templates do not escape for you

$set = tengine.add($set, "raw", '<h1>{{ .title }}</h1>');
$set = tengine.add($set, "safe", '<h1>{{ .title | html }}</h1>');
def data as json.Value init json.map({"title": "Tea & <i>cake</i>"});
<h1>Tea & <i>cake</i></h1>
<h1>Tea &amp; &lt;i&gt;cake&lt;/i&gt;</h1>
11 / 23

Building HTML in code: the html module

for (def ev in $events) {
    def day as html.Node init html.text(showDate($ev.start));
    def kids as list of html.Node init [];
    $kids[] = html.element("strong", [], [$day]);
    $kids[] = html.text(" " + $ev.summary + ", " + $ev.location);
    $items[] = html.element("li", [], $kids);
}
return html.render(html.element("ul", [], $items));
<li><strong>03 December 2026</strong> Jennifer meetup, Vienna</li>
<li><strong>14 January 2027</strong> Q&amp;A: your first blog, Online</li>
12 / 23

Writing the site with fs

func writeFile(file as string, content as string) {
    fs.mkdirAll(path.dir($file));
    fs.writeString($file, $content);
    io.printf("wrote %s\n", $file);
}
$ jennifer run build.j
wrote public/posts/feeds/index.html
wrote public/posts/tea-and-templates/index.html
wrote public/posts/hello-blog/index.html
wrote public/index.html
...
13 / 23

The home page

The home page: three posts and two upcoming events

14 / 23

A post page

The post Tea and templates in a browser

15 / 23

A feed for readers

for (def p in $posts) {
    def link as string init "{$url}/posts/{$p.slug}/";
    def e as feed.Entry init feed.entry($p.title, $link);
    $e = feed.entryId($e, $link);
    $e = feed.entryPublished($e, $p.date);
    $e = feed.entrySummary($e, $p.summary);
    $entries[] = $e;
}
def f as feed.Feed init feed.feed($title, $url);
$f = feed.feedUpdated($f, $posts[0].date);
return feed.addAll($f, $entries);
16 / 23

The RSS it writes

$ xmllint --format public/feed.xml | head -n 13
<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>Ada's notes</title>
    <link>https://blog.example.org</link>
    <lastBuildDate>Mon, 16 Nov 2026 00:00:00 +0000</lastBuildDate>
    <item>
      <title>Feeds, calendars and a card</title>
      <link>https://blog.example.org/posts/feeds/</link>
      <guid>https://blog.example.org/posts/feeds/</guid>
      <pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate>
      <description>RSS for readers, iCalendar for events, ...
17 / 23

Upcoming events as a calendar

def doc as toml.Value init toml.decode(fs.readString($file));
for (def i in 0..toml.length($doc, "/event")) {
    def e as toml.Value init toml.get($doc, "/event/{$i}");
    def ev as ical.Event init ical.event(
        toml.asString($e, "/id"),
        toml.asDatetime($e, "/start"),
        toml.asDatetime($e, "/end"),
        toml.asString($e, "/title"));
    $ev = ical.locate($ev, toml.asString($e, "/place"));
    if (time.after($ev.start, time.now())) {
        $events[] = $ev;
18 / 23

The events.ics file

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Jennifer//ical//EN
BEGIN:VEVENT
UID:meetup-2026-12@blog.example.org
DTSTAMP:20261203T180000Z
DTSTART:20261203T180000Z
DTEND:20261203T200000Z
SUMMARY:Jennifer meetup
LOCATION:Vienna
END:VEVENT
...
19 / 23

A contact card for the author

def c as vcard.Card init vcard.card($site["author"]);
$c = vcard.withName($c, $site["family"], $site["given"]);
$c = vcard.addEmail($c, $site["email"]);
$c = vcard.withUrl($c, $site["url"]);
$c = vcard.withNote($c, "Writes about Jennifer.");
return vcard.encode($c);
BEGIN:VCARD
VERSION:4.0
FN:Ada Example
N:Example;Ada;;;
EMAIL:ada@example.org
...
20 / 23

Previewing with a tiny web server

# serve.j - preview public/ at http://127.0.0.1:8080/
use httpd;
use io;

def srv as httpd.Server init httpd.listen("127.0.0.1:8080");
io.printf("preview at http://127.0.0.1:8080/ (Ctrl-C stops)\n");
while (true) { # lint-disable: L105
    def req as httpd.Request init httpd.accept($srv);
    io.printf("%s %s\n", httpd.method($req), httpd.path($req));
    httpd.serveDir($req, "public");
}
21 / 23

What the server sees

$ jennifer run serve.j
preview at http://127.0.0.1:8080/ (Ctrl-C stops)
GET /
GET /favicon.ico
GET /posts/tea-and-templates/
GET /favicon.ico
22 / 23

Where to go next

23 / 23