Build a Gratitude Journal in Eleventy with Beeminder Tracking

An Eleventy site that works as a gratitude journal and media log and reports to Beeminder. It covers HTML escaping in Nunjucks, timezone handling, and collections.

By
Brennan Kenneth Brown
Published
Reading time
5 minutes
Level
Intermediate
You need
  • An Eleventy project
  • A Beeminder account (optional)
Open handwritten manuscript book
Encoded letter of Gabriel Luetz d Aramon

This guide builds a gratitude journal and media log with Eleventy, where each day's entry is one Markdown file committed to GitHub. Beeminder tracks those commits so a missed day costs money. I wanted a daily record of what I'm grateful for and of the books, videos and music I consume, without the friction of separate tools like Letterboxd and Storygraph. The result is a small stand-alone site, the commonplace log.

Beeminder's GitMinder syncs with commits pushed to a specific GitHub repository. GitHub's API now limits tracking to one repository at a time, which suits this project: one repo, one commit per day.

What does the site need to do?

My original spec for the site:

  • An ultra simple brutalist 11ty blog called "daily gratitude", at the repo commonplace.
  • Extremely simple, no CSS framework, monospace web fonts, etc.
  • Extremely accessible as well, good-looking on desktop and mobile without any responsive design
  • Homepage will render the date and note of gratitude of that day, it will be more like microblogging, so no titles, tags, images, etc.
  • Each month of posts grouped.
  • In addition to gratitude, I think it would be fun to also use this daily microblogging to track what I consume (books, videos, music), locations I go, quotes, anything else like that like a commonplace book.
  • Each type of data /media tracked has its own emoji/colour, and they're all optional.

How do I set up the project?

I used Eleventy with Nunjucks templates. The bugs I hit were timezone shifts, Nunjucks escaping and collection filtering, covered below. The project structure:

src/
  _includes/
    base.njk
    post.njk
  posts/
    2025-01-01.md
    2025-01-02.md
  index.njk
  css/
    style.css

Each post would be a simple markdown file with YAML frontmatter containing all the different types of data I wanted to track:

---
date: 2025-01-02
gratitude: "The silence of early morning before anyone else is awake is precious."

books:
  - title: "The Dispossessed"
    author: "Ursula K. Le Guin"
    status: "reading"
    pages: 102

videos:
  - title: "Static Site Generators Explained"
    creator: "Fireship"
    url: "https://youtube.com/watch?v=example"
    duration: "12m"

music:
  - title: "Nightswimming"
    artist: "R.E.M."
    album: "Automatic for the People"
    plays: 3
---

This structure is easy to write and to track in Git. The Beeminder integration works by committing a new Markdown file each day, with GitMinder pointed at the repository.

Why does Nunjucks show raw HTML tags on my page?

When I rendered posts on the homepage, the raw HTML tags were visible as text. Nunjucks escapes HTML by default. That protects against untrusted input but breaks rendering of your own content. The fix was adding the | safe filter to the content in the base layout:

<main id="main">
  {{ content | safe }}
</main>

Only use | safe on content you control.

Why are my Eleventy post dates off by one day?

I'd create a post dated 2025-01-02, but it would show up on the homepage as January 1st. Or worse, it would show up in the wrong month entirely in the archives. December posts were appearing in November.

The issue? JavaScript's Date object was interpreting my YAML dates as local time and then converting them based on my timezone. Since I'm in a negative UTC timezone, dates were being shifted backward. A post from January 2nd at midnight was becoming January 1st at 1 PM the previous day. This is a known pitfall in the 11ty docs.

The solution required two fixes:

First, parse all dates as UTC by appending the timezone:

const date = new Date(dateObj + 'T00:00:00Z');

Second, use string comparison instead of date math for sorting:

.sort((a, b) => {
  return String(b.data.date).localeCompare(String(a.data.date));
})

Even with these fixes, I hit another timezone snag. When grouping posts by month, January 1st was showing up in December 2024! The issue was that date.getFullYear() and date.getMonth() were still converting to local time. The final solution was to use UTC methods explicitly:

const utcYear = date.getUTCFullYear();
const utcMonth = date.getUTCMonth();
const monthKey = `${utcYear}-${String(utcMonth + 1).padStart(2, '0')}`;

Use UTC methods everywhere when working with dates in JavaScript.

How do I build a latest-post and monthly archive collection?

I wanted the homepage to show the latest post in full, then monthly archives for everything else. First, a custom collection for the latest post:

eleventyConfig.addCollection("latest", function(collectionApi) {
  return collectionApi
    .getFilteredByGlob("src/posts/**/*.md")
    .sort((a, b) => String(b.data.date).localeCompare(String(a.data.date)))
    .slice(0, 1);
});

But my collections.all was returning 3 items when I only had 2 posts. Turns out, Eleventy was including the index.njk file itself as a collection item. The fix was to use the specific glob src/posts/**/*.md, as in the collections here.

I also needed to group posts by month, which meant creating another custom collection:

eleventyConfig.addCollection("byMonth", function(collectionApi) {
  const posts = collectionApi.getFilteredByGlob("src/posts/**/*.md");
  const byMonth = {};
  
  posts.forEach(post => {
    let date;
    if (typeof post.data.date === 'string') {
      date = new Date(post.data.date + 'T00:00:00Z');
    } else {
      date = post.data.date;
    }
    const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
    
    if (!byMonth[monthKey]) {
      byMonth[monthKey] = {
        year: date.getFullYear(),
        month: date.toLocaleString('en-US', { month: 'long', timeZone: 'UTC' }),
        monthKey: monthKey,
        posts: []
      };
    }
    
    byMonth[monthKey].posts.push(post);
  });
  
  return Object.values(byMonth).sort((a, b) => {
    return b.monthKey.localeCompare(a.monthKey);
  });
});

The archive logic had its own quirks. I initially excluded the entire month of the latest post from the archives, which meant January 1st disappeared when January 2nd was the latest post. The fix was to exclude only the single latest post, not the whole month:

{% for post in month.posts %}
  {% if not (collections.latest and post.data.date == collections.latest[0].data.date) %}
    <!-- render post -->
  {% endif %}
{% endfor %}

Why are my individual posts blank?

Archive links gave a 404 or an empty page because the posts weren't using any layout template.

I had to create a dedicated post layout _includes/post.njk and then add layout: ../_includes/post.njk to each post's frontmatter. But the layout needed to access the frontmatter data differently than I expected.

In the homepage template, I could access a post as post.data.gratitude. But in the individual post layout, the data is available directly as gratitude. This is Eleventy's data cascade: templates have different contexts depending on whether they render a collection item or the page itself.

How do I style the journal?

I kept the design brutalist, like brennan.day (see how that site is built). No CSS framework. No preprocessors. Just vanilla CSS with CSS custom properties for the Gruvbox Dark colour scheme:

:root {
  --bg: #282828;
  --fg: #ebdbb2;
  --bg0-h: #1d2021;
  --gray: #928374;
  --red: #fb4934;
  --green: #b8bb26;
  --yellow: #fabd2f;
  --blue: #83a598;
  --purple: #d3869b;
  --aqua: #8ec07c;
  --orange: #fe8019;
}

Each content type gets its own color-coded left border:

  • 🙏 Gratitude: Yellow
  • 📚 Books: Blue
  • 📺 Videos: Purple
  • 🎵 Music: Green
  • 📍 Locations: Red
  • 💬 Quotes: Aqua
  • 📝 Notes: Orange

The CSS is under 200 lines total. Monospace font stack ('Courier New', Courier, monospace). Fixed width container at 600px. No media queries needed as it just works on mobile because of the simplicity.

What else does the site need?

Once the core worked, I added RSS feed, sitemap, robots.txt, custom 404 page, social meta tags, favicons, and a footer with proper attribution. I even made the header clickable back home with a subtle yellow hover effect. Cache busting on the CSS means no more hard refreshes for visitors to see style updates.

Where is the code?

The code is open source at github.com/brennanbrown/commonplace, and the live site is at log.brennan.day. Each morning I commit a new Markdown file, and Beeminder tracks the commit.