Skip to content

Instantly share code, notes, and snippets.

@eaton
Last active December 3, 2023 17:29
Show Gist options
  • Save eaton/e77dcf42683a7e455499ae44966ab226 to your computer and use it in GitHub Desktop.
Save eaton/e77dcf42683a7e455499ae44966ab226 to your computer and use it in GitHub Desktop.
Basic recipe for using 11ty to spit out arbitrary data
Eleventy can process a bunch of markdown files into HTML for a blog, but it's also handy for turning big data files into individual HTML pages. https://www.11ty.dev/docs/data-global/ and https://www.11ty.dev/docs/pagination/ have the skinny.
project folder
├─ .eleventy.js <-- control/override plugins, templating, directory names, etc
├─ src <-- Your content, data files, templates, etc
│ ├─ _data <-- JSON files you put here become part of the 'global data'
│ │ └─ foo.json <-- any template can use this data as {{ data.foo }}
│ └─ foo-things.html <-- uses 'pagination' to output one page for each record in foo
└─ dist <-- Where 11ty spits out the final/compiled output
└─ foo-things <-- the path specified in foo-pages.html's permalink property
├─ foo-data-1.html <-- one file for each item in foo.json
├─ foo-data-2.html
└─ foo-data-3.html
---
pagination:
data: foo
size: 1
alias: item
permalink: "foo-things/{{ item.filename | slugify }}.html"
---
<html>
<head>
<title>{{ item.name }}</title>
</head>
<body>
<h1>{{ item.name }}</h1>
<p>{{ item.description }}</p>
</body>
</html>
[
{ "filename": "foo-data-1", "name": "first item", "description": "some stuff" },
{ "filename": "foo-data-2", "name": "second item", "description": "some stuff" },
{ "filename": "foo-data-3", "name": "third item", "description": "some stuff" }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment