Skip to content

Introduction

In part one, I covered the design and frontend technologies of my photography portfolio www.sebastiankleinphotography.com.

In this second article, I will describe how I built the site using the Eleventy static site generator, including:

  • Highlighting some of Eleventy’s features
  • My approach when setting things up
  • Individual solutions for the portfolio
  • Stumbling blocks, their causes, and solutions

As a TYPO3 developer, I will occasionally compare procedures with that CMS.

From LAMP to the Jamstack

I usually develop and manage websites based on TYPO3 CMS. This developer blog has also been running on TYPO3 since 2015.

The photography portfolio was a good opportunity to try out a different system. Initially, I had considered building a Symfony application.
However, I quickly decided to use a static site generator (SSG); the high level of flexibility in templating was the deciding factor. Not using a database and deploying static HTML pages appealed to me.

Why Eleventy?

I have to admit, I did not really compare the various SSGs in detail beforehand. I knew a few of the names, but many frontend developers repeatedly emphasized one in particular: Eleventy.

The project is associated with two other names:

  • 11ty (the overarching organization and community behind the project)
  • Build Awesome (a rebranding that took place in 2026 under the Font Awesome umbrella)

After reviewing Eleventy’s features and workflow, I cloned the official blog starter repository and began making my adjustments.

The blog section ("Notes")

Thanks to the starter repository, I immediately had a fully functional blog with a list view, tags, an RSS feed, and browse navigation to the previous and next posts.
Using the “Draft” feature, I can mark blog posts as in progress; they will then render in development mode but be excluded from the build.

Eleventy has its own development server with hot reloading. In development mode, changes are visible immediately.

Using this repository as a foundation, you can quickly get your own independently hosted blog up and running.

First, I customized the blog structure to suit my needs and set up a separate page layout for blog posts. I liked how the homepage displayed the three most recent blog posts, so I incorporated that into my portfolio.

Choosing the template language

Eleventy supports many template formats, from plain HTML to Markdown and Liquid, as well as user-defined languages.
You don’t have to stick to just one format; instead, you configure a list of the languages you want to process.

In this project, I wanted to retain full control over the final HTML and styling. If I need an additional HTML attribute in one place or want to style a single element differently, I allow myself that freedom.

This differs significantly from my day-to-day work in the CMS, where I use components that are as standardized as possible with well-defined options. For a website that’s maintained over the long term—with several thousand subpages and a dozen editors—you need reliable structures and clean content; custom code can seriously mess things up during an upgrade or relaunch.

That's why I write all templates in standard HTML and use the Nunjucks template language for control structures and other necessary functions.
You can define page-wrapping layouts as well as smaller, reusable templates (includes)—similar to the Fluid Rendering Engine in TYPO3 with its layouts and partials.

Filters and shortcodes

Nunjucks is one of the languages in Eleventy that supports both filters and shortcodes.

Filters are functions that can be applied to variables. These include text processing of strings (nl2br, upper) and working with arrays or objects (sort(), groupby). Various filters are already provided by Nunjucks, and Eleventy also lets you define your own. You can also chain them together:

<p class="c-photo__description">{{ photo.description | safe | nl2br }}</p>

Shortcodes are useful for generating reusable HTML structures, embedding media, or processing passed parameters. You can compare them to Fluid ViewHelpers or Fluid Components in TYPO3.

I have created three shortcodes to generate images in a specific format. Further down, I will go into more detail; here is an example of using my imageLargerSide shortcode:

{% set altText %}
    {{- photo.alt if photo.alt else photo.title -}}
{% endset %}
{% set viewTransitionName %}view-transition-name: photo-{{ photo.fileSlug }};{% endset %}
{% imageLargerSide photo.image, altText, 320,
    { formats: ["avif", "webp", "auto"] },
    { class: "c-photo-list__img", style: viewTransitionName } %}

Directory structure

I have configured the directories for Eleventy as follows:

ConfigurationValueDescription
dir.input_srcSource files (templates, SCSS, JavaScript, images, webfonts, …).
dir.includes_includesTemplates in this subdirectory are not directly processed by Eleventy. This is useful, for example, for page layouts that are applied to different templates. (path relative to dir.input)
dir.data_dataDirectory for data that is globally available in all templates. For example, this is where my photo metadata is stored. (path relative to dir.input)
dir.output_siteTarget directory for the build process.

Within the input directory, Eleventy automatically transforms all files into HTML documents whose language has been configured as a template format.

For a clearer overview, I've highlighted the file names shown in the screenshots.

  • Yellow: reusable template includes
  • Green: pages (will be processed into HTML documents, robots.txt, …)
  • Blue: data (see data sources)
  • Violet: assets (stylesheets, JavaScripts, images, icons, …)

You can see two “img” directories in the screenshots. The first one, located inside the input directory (_src), contains all the photos for the image galleries. When Eleventy builds the pages, these images are optimized to their final sizes and converted to AVIF/WebP. The images and other files located in the “public” directory are not processed by Eleventy, but copied as-is directly to the target directory. This is useful for favicons or already-optimized Open Graph images.

Static files can be copied by configuring addPassthroughCopy() (Eleventy documentation). When using Vite, add publicDir configuration (Vite documentation).

By default, the URL path of the generated page is identical to the structure in the input directory.

You can use the permalink key to define a different path:

permalink: "/album/new-york-city-the-polaroids-2015/"

The build process will then write the HTML template into this directory. Eleventy will report an error if, accidentally, multiple templates have the same target path.

Data sources

With Eleventy, you can provide data to templates in various ways.

Before Eleventy renders the templates, data from all sources is merged (data cascade). If data is defined in multiple places, Eleventy prioritizes it from local to global.

I can therefore override globally defined default values in selected directories (via *.11tydata.js) as well as in a single template (using front matter).

I use this, for example, for individual page titles, a different layout for the blog section, and assigning Open Graph images.

Rendering of the image galleries

Maintaining the photo metadata

The metadata for all photos in the image galleries is written in Markdown files with YAML frontmatter and stored centrally in the data directory.

A custom JavaScript reads and validates this metadata. It sorts all photos by the date they were taken. Finally, it determines the previous and next photos to enable the browse navigation in the photo detail view.

_src/_data/photos/paris-2026/paris-2026-polyphemus.md:

---
date: 2026-06-20
title: Polyphemus surprising Acis and Galatea
description: |
    Fontaine Médicis, Jardin du Luxembourg.
    Paris 2026.
alt: "Group of statues at Fontaine Médicis, representing figures from Greek mythology. The giant Polyphemus, in bronze, gazes down at the lovers Acis and Galatea, sculpted in white marble."
image: "/img/gallery/paris-2026/paris-2026-polyphemus.jpg"
dateTaken: "2026-03-28"
album: album.paris2026
genre: [ "Travel" ]
media: "Film"
film: film.portra160
camera: camera.sl66
lens: lens.rollei80
aperture: 4.8
shutter: "1/250"
iso: 160
---

While dateTaken contains the time the image was captured (optionally in the format “YYYY-MM”), date serves as the last modification date for the sitemap.

To ensure that the names of films, cameras, and lenses are always displayed consistently, they are defined in separate JavaScript files. In the front matter, the names are referenced using a key (e.g., film.portra160).

Genres and media types are checked against the configured lists to avoid duplicates caused by typos (“Landscape” vs. “Landscapes”).

_src/_data/genreDescriptions.js:

export default {
    Landscape: {
        text: "",
        featuredImage: "/img/gallery/iceland-2024/iceland-2024-mountains-at-svinafellsjoekull-1.jpg",
    },
    Portrait: {
        text: "",
        featuredImage: "/img/gallery/paris-2026/paris-2026-blossoms-phone.jpg",
    },
    Street: {
        text: "",
        featuredImage: "/img/gallery/nyc-2015-polaroids/pola-nyc2015-crossing.jpg",
    },
    // […]
};

Photo detail view

I use Eleventy’s pagination feature in the front matter of the photo detail template. I pass the photos object—which was generated from the photo metadata—as its data; Eleventy then generates a separate HTML document for each photo.
In the front matter, I also read the filename of the metadata file (using photo.fileSlug) and use it as part of the permalink.

In the Nunjucks template, I then read each image's attributes and specify the desired markup.

---
pagination:
    data: photos
    size: 1
    alias: photo
permalink: "/photo/{{ photo.fileSlug }}/"
eleventyComputed:
    title: "{{ photo.title }} | Photo"
eleventyNavigation:
    parent: "Photos"
---

<div itemscope="itemscope" itemtype="https://schema.org/Photograph">
    <div class="c-section c-section--centered">
        <div class="c-photo-details">
            {% set altText %}
                {{- photo.alt if photo.alt else photo.title -}}
            {% endset %}
            {% set viewTransitionName %}view-transition-name: photo-{{ photo.fileSlug }};{% endset %}
            <div class="c-photo-details__stage {% if photo.media == 'Instant' %}c-photo-details__stage--shadow{% endif %}">
                <!-- "imageLargerSide" is a custom shortcode, explained further below -->
                {% imageLargerSide photo.image, altText, 1200, { widths: [450, 768, 1200] }, { class: "c-photo-details__img", loading: "eager", sizes: "auto", itemprop: "image", style: viewTransitionName } %}
            </div>

            <!-- further markup and photo metadata -->
        </div>
    </div>
</div>

List views for Media/Genre

For the list views, I added two Collections to the Eleventy configuration.

eleventy.config.js:

export default async function (eleventyConfig) {
    eleventyConfig.addCollection("genres", function () {
        return Array.from(new Set(photos.flatMap(photo => photo.genre || []).filter(Boolean))).sort();
    });

    eleventyConfig.addCollection("mediaTypes", function () {
        return Array.from(new Set(photos.map(photo => photo.media).filter(Boolean))).sort();
    });
};

The Eleventy pagination also processes these collections, generating a separate HTML document for each genre and media type.

The global data directory contains the files mediaDescriptions.js and genreDescriptions.js, whose contents are available in all templates. From these files, I retrieve the “featured image” for each genre/media, which is rendered at double size.
In the same way, I can add an introduction text for each genre (which I haven't had time for yet).

_src/photos/genre.njk:

---
pagination:
  data: collections.genres
  size: 1
  alias: genre
permalink: "/genre/{{ genre | slug }}/"
eleventyComputed:
    title: "Genre: {{ genre }}"
eleventyNavigation:
    parent: "Photos"
---
<div class="c-section c-section--centered">
    <div class="c-photo-gallery">
        <div class="c-photo-gallery__intro">
            <div class="c-photo-gallery__intro-content">
                <h1><span class="u-font-light">Genre</span><br>
                    {{ genre }}</h1>
                {% if genreDescriptions[genre].text %}
                    {{ genreDescriptions[genre].text | safe }}
                {% endif %}
            </div>
        </div>
        <div class="c-photo-gallery__images">
            <ul class="c-photo-list">
                {% if genreDescriptions[genre].featuredImage %}
                    {% for photo in photos %}
                        {% if photo.image == genreDescriptions[genre].featuredImage %}
                            <!-- renders featured image -->
                        {% endif %}
                    {% endfor %}
                {% endif %}
                {% for photo in photos | sortByDateTakenDesc %}
                    {% if photo.genre and genre in photo.genre %}
                        {% if photo.image != genreDescriptions[genre].featuredImage %}
                            <!-- renders all other images, sorted by date taken -->
                        {% endif %}
                    {% endif %}
                {% endfor %}
            </ul>
        </div>
    </div>
</div>

Photo albums

Each album has individual markup and styling. I deliberately create them manually.

I have extended the base layout so that I can reference additional stylesheets and JavaScript files in the front matter:

---
title: "Iceland 2024"
ogImage: "/img/share/og-album-iceland-2024.png"
permalink: "/album/iceland-2024/"
album: "Iceland"
year: 2024
eleventyNavigation:
    parent: "Photos"
additionalStyleSheets:
    - "/assets/css/add-on/album-iceland2024.scss"
---

Image transformations

Eleventy comes with the “Image Utility” plugin, which has some useful features for responsive images:

  • Multiple image sizes can be generated from a single image
  • An image can be rendered in multiple file formats (JPEG, AVIF, WebP, …)
  • The most appropriate HTML markup (<img> or <picture>, <source> with the proper attributes) is automatically generated based on the image attributes
  • You can configure default values for sizes and formats

Two examples of image definitions in Nunjucks:

<img src="./possum.png" alt="A possum parent and two possum kids hanging from the iconic red balloon" width="600">

<img src="./possum.png" alt="A possum parent and two possum kids hanging from the iconic red balloon"
		 eleventy:widths="420,800" eleventy:formats="webp,avif,jpeg">

The HTML markup generated by Eleventy:

<img src="/path/to/image/YwgtEzywUG-600.webp"
     alt="A possum parent and two possum kids hanging from the iconic red balloon"
     loading="lazy" decoding="async"
     width="600"  height="1174">

<picture>
    <source type="image/webp"
            srcset="/path/to/image/YwgtEzywUG-420.webp 420w, /path/to/image/YwgtEzywUG-800.webp 800w"
            sizes="auto">
    <source type="image/avif"
            srcset="/path/to/image/YwgtEzywUG-420.avif 420w, /path/to/image/YwgtEzywUG-800.avif 800w"
            sizes="auto">
    <img loading="lazy" decoding="async" src="/path/to/image/YwgtEzywUG-420.jpeg"
         alt="A possum parent and two possum kids hanging from the iconic red balloon"
         width="800" height="1566"
         srcset="/path/to/image/YwgtEzywUG-420.jpeg 420w, /path/to/image/YwgtEzywUG-800.jpeg 800w"
         sizes="auto">
</picture>

This is very convenient. However, one thing worth noting is that all image sizes are always specified by width; the image height is determined automatically. It is not possible to specify the desired image height.

This approach makes sense, since the Image Utility generates responsive images and their display also depends on the browser width.

There were two cases in the portfolio that I could not easily implement in Eleventy:

  1. A portrait-oriented image and a landscape-oriented image side by side, with the same image height.
  2. Listing all photos while maintaining the aspect ratio (longer side 320px)

Custom shortcodes for image rendering

As a solution, I created three shortcodes for my project:

  1. Image size based on a specified height
  2. Image size based on the longer side of the original
  3. Image with a lightbox link: The generated image is linked to a higher-resolution version of itself

I intended to publish the shortcodes and share the links here. However, they are currently designed specifically for my project and need to be adapted for general use.

Frontend build using Vite

I still prefer writing my stylesheets with SCSS. One reason is that I do not want to declare some “internal” variables as CSS Custom Properties. I also like using mixins, maps, and @for loops to abstract certain parts of the code.

There are several ways to transform SCSS in Eleventy. The simplest is the addWatchTarget() function, which is used in the blog repository. A Sass-Extension is also available.

My requirements

The frontend build should perform the following tasks:

  • Minifying stylesheets and JavaScript files (removing whitespace and comments)
  • GZIP compression of CSS, JS, and HTML
  • Add hashes to asset filenames

Vite

To meet all requirements, I configured @11ty/eleventy-plugin-vite and vite-plugin-compression2.

However, setting up Vite turned out to be more complicated than I had initially imagined. I experienced some initial problems, especially when processing images.

Stumbling blocks

I didn't set everything up correctly from the start. Maybe the following pointers will help someone learn from my mistakes.

Invalid image paths when using root-relative paths

There is only one example of how to use images in the blog repository. The fourth post references an image that is located in the same directory as the template:

<img src="./possum.png" alt="">

I want to store my photos in a central directory. When I used them in templates, I tried setting paths relative to the project root. However, this resulted in incorrect paths during the build, so the image couldn't be displayed:

<!-- Template -->
<img src="/public/img/image.jpg" alt="">

<!-- Generated HTML document -->
<img src="content/public/img/image.jpg" alt="">

I'm not the first person to stumble across this. In the related issue, I found the suggestion to adjust the directory structure.

The cause of the issue is: Absolute paths are relative to the input directory, not to the project root.

Since my images and templates are now both located under “_src” (the input directory), specifying image paths like /img/gallery/path/to/image.jpg works as expected.

Double image transformation through Vite

This was a configuration error on my part. The three image shortcodes wrote the generated images directly to the output directory. Vite reprocessed these images during the build process, even though they had already been optimized by the Eleventy Image Utility.

Vite deleted my lightbox images

At the beginning of the year, Vite had an issue: image paths in links weren’t being recognized as assets (the issue was closed as a duplicate, and the problem was resolved in June).

This meant that when I was building my portfolio, my lightbox images were missing at the end of the build process. Vite deletes all assets that can’t be identified.

As a temporary workaround, I had the linked images from the lightbox shortcode generated into the “public” directory. As the final step in the build process, a closeBundle() hook moved the lightbox images and cleaned up temporary files and directories.

Now, all image shortcodes output the generated files into the “public” directory so that Vite copies them unchanged to the target directory.

My shortcodes have created additional image copies

All three image shortcodes have read the dimensions of the original image as a first step:

let metadataOrig = await Image(fullSrc, {
    widths: [null],
    formats: ["jpeg"],
});
let {width: origW, height: origH} = metadataOrig.jpeg[0];

However, this call to Image() (from the Image Utility) not only returned the desired information, but also generated a full-size image and saved it to a new “img” directory in the project root.

The solution was to set statsOnly: true (Documentation).

Closing words

For the initial release of the portfolio, it wasn’t essential to get everything technically perfect. I’ve already started making improvements and have more planned.

I have not regretted choosing Eleventy. It gives me a lean and flexible setup. I can easily publish new photos and blog posts.

Now that this article is finally finished, I can focus on adding new content to the portfolio soon. After all, I have taken my camera out on several occasions in the meantime.

Back to news list