Aging Coder — Modernized Eleventy Site
This repository is the Aging Coder blog (Eleventy). The site has been modernized to use Pico CSS, lightweight custom styles, improved image handling, and a few developer utilities to make authoring and maintenance easier.
Quick commands
- Install dependencies:
npm install- Build the static site (writes to
_site/):
npm run build- Serve locally with Eleventy (live-reload):
npm run serveHigh-level architecture
- Eleventy (
.eleventy.js) is the static site generator and central place for collection, shortcode, filter, and transform configuration. - Markdown is processed with
markdown-itplus plugins for KaTeX and anchors. Mermaid fenced blocks are rendered into<pre class="mermaid">...</pre>so client-side Mermaid can initialize them. - Collections provided:
posts,categories,tags,featured,feedPosts, andstatic-snippets. - A transform rewrites plain
<img>markup in generated HTML to addloading="lazy",decoding="async", a classimg-inline, and wraps the image in<p class="with-image">so CSS can style inline images consistently. - Shortcodes:
thumbnail— responsive thumbnail generator (uses@11ty/eleventy-imgfor local images, falls back to plain<img>for remote images).mermaidpaired shortcode for embedding Mermaid blocks in templates.snippetRawLink— link to raw markdown for a snippet.
Where to put content
- Posts
- Put posts under
src/posts/. Nested folders are supported — the site canonicalizes post permalinks so files moved into nested folders (for examplesrc/posts/older/) continue to publish at/posts/<slug>/. - Example frontmatter:
- Put posts under
---
title: "My Post"
date: 2025-10-01
tags: [eleventy, notes]
category: Blog
draft: true # remove or set to false to publish
featured: false
description: "A short two-sentence summary shown in listings"
----
Static snippets
- Add Markdown files to
src/static-snippets/and include asnippet: namevalue in frontmatter. These are loaded into thestatic-snippetscollection and getdata.rawMarkdownanddata.raw_permalinkattached for easy embedding. - Use the
findSnippetByNamefilter/shortcode from templates to pull a snippet by name.
- Add Markdown files to
-
Mermaid diagrams
- Use fenced code blocks in Markdown:
```mermaid
graph TD; A-->B;
`` `- Or use the paired Nunjucks shortcode in templates:
{% mermaid %}
graph TD; A-->B;
{% endmermaid %}- The code block is rendered to
<pre class="mermaid">…</pre>so client-side Mermaid (if included) converts it to a diagram.
Thumbnail and image handling
- Use the
thumbnailNunjucks shortcode where you want a feature image:{% thumbnail post.data.imagefeature, post.data.title %}.- For local images this generates WebP + JPEG variants and
srcsetusing@11ty/eleventy-imgand writes files into_site/img/. - For remote images it emits a lazy
<img>fallback.
- For local images this generates WebP + JPEG variants and
- The
wrapImagestransform ensures inline images get consistent attributes and a wrapper so CSS can style them.
Drafts and publishing workflow
-
There are two common ways this project handles drafts: frontmatter flags (manual) and the convenience npm scripts in
package.json(npm run draftandnpm run publish). Below is the precise behavior of those helper scripts so you know what they do and how to call them. -
Frontmatter method (manual): Mark a post as a draft by adding
draft: trueto its frontmatter. To publish a draft using this method: removedraft: true(or set it tofalse) and run the production build. -
Npm scripts method (convenient): Use the
npm run draftscript to create a new draft post:
npm run publish- Notes & recommendations:
- Because
js/publish-draft.jsonly scans the immediate files insrc/posts/, drafts located in nested directories (for examplesrc/posts/older/my-draft.md) will not be found by thepublishscript. If you rely on nested draft locations you can either move drafts to the top-levelsrc/posts/before runningnpm run publishor I can update the script to search recursively. - The
create-post.jsscript enforces a title argument and marks the new post as a draft. If you want a different frontmatter template (for example to pre-fillcategoryortags) we can adjust the template in that script. - The publish script is conservative: it only removes a line that exactly matches
draft: true(case-insensitive) and otherwise preserves existing frontmatter formatting and fields.
- Because
Permalinks and moving files
- Posts under
src/posts/**are canonicalized so the output permalink ignores intermediate folders and only uses the file slug, e.g.src/posts/older/my-post.md->/posts/my-post/. This makes reorganizing old posts safe without changing the public URL. - Be cautious of duplicate slugs (two files named
my-post.mdin different folders will conflict);.eleventy.jsemits a console warning for duplicate slugs at build time.
Categories, tags, and featured
categoriesandtagscollections gather posts acrosssrc/posts/**(including nested folders). Categories are returned sorted alphabetically; each category entry containsname,size(post count), andposts(sorted by date newest-first).featuredcollects posts with a truthyfeaturedfrontmatter value and respects the same draft filtering.
Developer utilities and scripts
scripts/contains utility scripts used for maintenance or one-off tasks (image processing helpers, content generation, small data transforms). Each script is intended to be run from the project root with Node:
node scripts/<script-name>.js- Brief ideas of what scripts do (check each file for options):
- generate-descriptions.js — can be used to auto-provision
descriptionfrontmatter for posts (if integrated with an LLM). - apply-palette.js / screenshot-themes.js — helpers for theme previews and CSS palette automation.
- generate-descriptions.js — can be used to auto-provision
Filters and shortcodes summary
- Filters:
excerpt(prefersdescription, falls back to stripped content),sortByName,findSnippetByName, date filter vianunjucks-date. - Shortcodes:
thumbnail(Nunjucks async),mermaid(paired),snippetRawLink.
Adding a new post (quick)
- Create
src/posts/YYYY-MM-DD-slug.md(orslug.mdwhere you prefer). - Add frontmatter as shown above (include
descriptionfor better search/listing results). - Preview locally with
npm run serve(drafts are included by default when not running the production build env). - When ready, remove
draft: trueand run the production build withELEVENTY_RUN_MODE=build.
Tips and next steps
- Mermaid: include the Mermaid client script on pages where diagrams should render (the project may already include this in a template).
- Static snippets: use them to centralize frequently-used content snippets or reusable examples.
- Thumbnail usage: prefer local images for best performance (the shortcode will generate optimized variants).
- If you're adding many descriptions programmatically, consider rate limiting and batching requests when calling external APIs.
Changelog (recent)
- 2025-09-29: Modernized Eleventy setup, added image shortcodes and transforms, enabled Mermaid/KaTeX support, added static-snippets collection and developer scripts.
License and contributing
- See the repository root for LICENSE and contribution guidelines.