Skip to content

About

Blog pages for Eleventy with no templates to copy: post list, tags, archive, and feed

Resources

Stars

17 stars

Watchers

1 watching

Forks

Repository files navigation

eleventy-plugin-blog

Zero configuration blog features for Eleventy: a paginated blog, tags, categories, and a year and month archive.

Works with Eleventy 3 (Node.js 18 or later) and the Eleventy 4 alpha (Node.js 22.15 or later).

Website: sielay.github.io/eleventy-plugin-blog, built with the plugin itself. Its source is in site/.

Features

  • Tags, Categories and API to create new taxonomies (paginated)
  • Calendar (paginated)

Command-line tool

npx eleventy-blog adds the plugin to a site, writes and publishes posts, tidies tags, and checks the site before a deploy. See cli/README.md.

Installation

npm install --save eleventy-plugin-blog
# OR
yarn add eleventy-plugin-blog

Usage

Running the examples

Go to the folder with given example and run:

../../generate-examples.js -o . -n 500
npx @11ty/eleventy

The script writes 500 sample posts, and Eleventy builds every index for them.

Basic

See the zero configuration example. Add the plugin to your Eleventy configuration file.

// eleventy.config.js
import blog from "eleventy-plugin-blog";

export default function (eleventyConfig) {
  eleventyConfig.addPlugin(blog);
}

CommonJS configuration files work too:

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(require("eleventy-plugin-blog"));
};

The plugin treats every template under <input>/blog/ as a post, where <input> is your Eleventy input directory. Add posts there and build. The plugin adds the blog pages for you:

Page URL
Post list, paginated /blog/, /blog/page-2
Tag list /blog/tag/
One page per tag /blog/tag/<slug>/
One page per category /blog/category/<slug>/
Year and month archive /blog/2026/, /blog/2026/07/
Atom feed, when feed.url is set /blog/feed.xml

It also produces these collections, for your own templates:

  • blog all posts, paginated
  • blog_flat all posts, flat
  • pages all pages with front matter staticPage: true
  • tag posts grouped by tags, paginated
  • category posts grouped by categories, paginated
  • category_list list of all categories
  • tag_list list of all tags
  • calendar posts grouped by year or year and month, paginated

Posts with draft: true in their front matter stay out of every collection.

Eleventy 4: no collection per tag

Eleventy makes a collection for every tag, such as collections.food. The plugin's tag pages do not need them. On Eleventy 4, you can turn them off:

export const config = {
  keys: { tags: false },
};

Your own pages

The built-in pages use a plain layout. Pass layout to use your site's layout instead:

eleventyConfig.addPlugin(blog, {
  layout: "base.njk",
  feed: { url: "https://example.com", title: "My blog", author: "Ada" },
});

To replace one page, create a file at its path in your input folder. The plugin then skips its own version of that page.

Page Path to create
Post list blog-pages/index.njk
Tag list blog-pages/tags.njk
Tag page blog-pages/tag.njk
Category page blog-pages/category.njk
Archive blog-pages/calendar.njk
Feed blog-pages/feed.njk

To turn pages off, pass pages: false for all of them, or name the ones to drop: pages: { calendar: false, category: false }. The custom templates example turns them all off and brings its own.

Options

Pass options as the second argument to addPlugin.

eleventyConfig.addPlugin(blog, {
  itemsPerPage: 20,
  blogPostTemplate: "post.njk",
});
Option Default Description
input Eleventy input directory Folder that holds blog/
blogPaths <input>/blog/**/*.<ext> Globs for blog posts
allPaths <input>/**/*.<ext> Globs for every page
extensions All Eleventy formats Template extensions to match
itemsPerPage 10 Posts on each index page
blogSlug blog URL prefix for every index
blogPostTemplate none Layout applied to every post
sortBlog newest first Compare function for blog and blog_flat
defaultCategory blog Category for posts without one
pages true Built-in pages: true, false, or { tag: false, ... }
layout a plain layout Layout for the built-in pages
feed none { url, title, subtitle, author, limit, path }; url is required for a feed
lang en lang attribute of the plain layout
verbose false Log what the plugin collects

Permalinks for index pages

Each index page carries its full URL in url, for example /blog/, /blog/page-2, or /blog/tag/notes/. Build the permalink from it:

permalink: "{{ postslist.url }}{% if not postslist.url.endsWith('/') %}/{% endif %}index.html"

API

Example template for rendering Page[]

<ul>
{%- for post in postslist.items -%}
  <li>
    {%- include 'tile.njk' -%}
  </li>
{%- endfor -%}
</ul>

paginate(options): IndexPage[]

Create paginated index of pages

Options

Field Type Description
pages Iterable Collection of 11ty pages
slug String Slug to be applied (see notes below)
prefix String Slug prefix
title String Given title
meta Object | Undefined Additional data to bound to each index page (see generateCalendar
itemsPerPage Number Number of 11ty pages on each index page

Slugs will be generated as follows:

  • First page ${slug}
  • Every next page ${slug}/page-${pageNumber}

IndexPage

Field Type Description
title String Given title
slug String Generated slug (as described above)
pagenumber Number Number of given page (starting from 0)
url String Concatenated value from prefix and slug
total Number Number of pages
slugs Slugs
items Page[] 11typ pages on given page
...meta Anything that came from meta input

Slugs

Field Type Description
all String[] List of all pages slugs
next String | Null Slug of the next page
previous String | Null Slug of the previous page
first String | Null Slug of the first page
last String | Null Slug of the last page

Example template

---
title: Blog
pagination:
  data: collections.blog
  size: 1
  alias: postslist
permalink: "{{ postslist.url }}{% if not postslist.url.endsWith('/') %}/{% endif %}index.html"
---
{%- include 'postslist.njk' -%}

generatePaginatedBlog(eleventyConfig, Options)

Generates a paginated blog. It runs paginate over the blog globs and can apply a layout.

Options

Field Type Description
blogPostTemplate String | Undefined Path to blog post template
blog String[] Globs for blog posts
itemsPerPage Number Custom number of items per page

For a template example see paginate.

generateCalendar(eleventyConfig, Options)

Generates calendar grouping by years and months.

Options

Field Type Description
blog String[] Globs for blog posts
itemsPerPage Number Custom number of items per page

IndexPage objects generated here will be extended using meta field with

Field Type Description
year String Year for annual group
month String | Undefined Month for monthly group
type 'year' | 'month' Type of group
shortTitle String | Undefined Formatted title for month groups

See calendar.njk for a template.

generateTaxonomy(eleventyConfig, Options)

TBD

generateBooleanCollection(eleventyConfig, Options)

TBD

Filters

blog_top

TBD

blog_slug

TBD

blog_dateformat

TBD

blog_first

TBD

Made by

Made by Lukasz Sielski. I build small products and help businesses run themselves. See what else I make at sielay.com.

Kudos

Inspired by Jérôme Coupé

About

Blog pages for Eleventy with no templates to copy: post list, tags, archive, and feed

Resources

Stars

17 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages