Having covered the planning side of a community-driven site in the previous installment, this part turns to implementation: an Eleventy setup that accepts per-contributor pet submissions, builds profile pages from them, and deploys the result. The working example pits randomly chosen cats and dogs against each other in a weekly cuteness battle on the home page. Voting is out of scope here (though serverless functions could handle it); the focus is on the submissions themselves.
Project init and development scripts
Run npm init in a directory of your choice, then add Eleventy:
npm install @11ty/eleventy
The scripts section of the generated package.json can be replaced with the following, which provides a development command with Browsersync hot-reloading (npm run develop) and a build command for production (npm run build):
"scripts": {
"develop": "eleventy --serve",
"build": "eleventy"
},
Those commands call Node, which Eleventy requires, and run in a terminal—either standalone or one built into an editor such as VS Code. One more package is needed now: fast-glob, used later to combine data files.
npm install --save-dev fast-glob.
Directory configuration and the submission schema
Eleventy's input and output directories are customizable for organization. Creating eleventy.js at the project root sets the input to src and the output to public:
module.exports = function (eleventyConfig) {
return {
dir: {
input: "src",
output: "public"
},
};
};
Squarely a pets directory for incoming data, split into cat and dog subdirectories to reduce merge conflicts and keep the two kinds of submissions distinct:
pets/
cats/
dogs/
Each contributor sends a JSON file following this schema—one property per data point:
{
"name": "",
"petColor": "",
"favoriteFood": "",
"favoriteToy": "",
"photoURL": "",
"ownerName": "",
"ownerTwitter": ""
}
A CONTRIBUTING.md at the repo root documents the schema for submitters; GitHub surfaces its contents in the repository, and it is the natural place to note that favoriteFood, favoriteToy, and ownerTwitter are optional. A README.md works just as well, but a file dedicated to contributions is cleaner. Note that photoURL is a URL rather than an uploaded file—a choice made for security and hosting cost—though accepting real files is a legitimate alternative.
Combining the data sources
The site needs a single array per species, assembled from the individual files, so that templates can loop over them and the weekly battle can pick random entries. Eleventy permits Node module.exports inside _data, so one file can gather all cat files into one dataset and another can do the same for dogs. The filename in _data becomes the variable holding that dataset:
_data/
cats.js
dogs.js
The cat function follows; the dog version is identical apart from swapping "cat" for "dog".
const fastglob = require("fast-glob");
const fs = require("fs");
module.exports = async () => {
// Create a "glob" of all cat json files
const catFiles = await fastglob("./src/pets/cats/*.json", {
caseSensitiveMatch: false,
});
// Loop through those files and add their content to our `cats` Set
let cats = new Set();
for (let cat of catFiles) {
const catData = JSON.parse(fs.readFileSync(cat));
cats.add(catData);
}
// Return the cats Set of objects within an array
return [...cats];
};
This Node code is not obligatory for simpler Eleventy sites—if contributors instead appended to a single growing JSON file in _data, no combination step would exist at all. The individual-file approach, and therefore fast-glob, is chosen specifically to keep merge conflicts down.
Rendering the home page
Add a handful of sample JSON files to pets/cats and pets/dogs to have test data. The first page is index.njk in src, written in Nunjucks—one of several templating languages Eleventy supports. Start with the two unordered lists:
<ul>
<!-- Loop through cat data -->
{% for cat in cats %}
<li>
<a href="https://css-tricks.com/cats/{{ cat.name | slug }}/">{{ cat.name }}</a>
</li>
{% endfor %}
</ul>
<ul>
<!-- Loop through dog data -->
{% for dog in dogs %}
<li>
<a href="https://css-tricks.com/dogs/{{ dog.name | slug }}/">{{ dog.name }}</a>
</li>
{% endfor %}
</ul>
The cats and dogs references match the filenames in _data; within each loop, JSON keys are reached with dot notation and printed as Nunjucks variables in double curly braces, e.g. {{ cat.name }}.
Generating one page per pet
Individual profiles live at [pet type]/[name-slug]. The recommended way to generate pages from data is Eleventy's pagination. The pagination templates go at the root of src, but any directory inside src that Eleventy can discover will do:
src/
cats.njk
dogs.njk
Front matter then supplies the pagination settings, shown here for cats:
---
pagination:
data: cats
alias: cat
size: 1
permalink: "/cats/{{ cat.name | slug }}/"
---
data names the file in _data. alias is optional but gives a handle for the current item in the paginated array. size: 1 produces one page per data item. The permalink must be declared too: it uses that alias to read the name key and passes it through the built-in slug filter, which lowercases and converts spaces to dashes to make the value URL-friendly.
Run npm run develop, which starts the local server and prints a URL in the terminal; build errors also surface there. A successful run creates public containing:
public/
cats/
cat1-name/index.html
cat2-name/index.html
dogs/
dog1-name/index.html
dog2-name/index.html
index.html
In the browser, the home page shows two linked lists—cat names and dog names.
Layouts, layout chaining and computed data
The generated pet pages are still empty. Eleventy looks for an _includes directory holding layouts and partials, and two layouts are needed:
src/
_includes/
base.njk
pets.njk
base.njk is HTML boilerplate whose <body> contains {{ content | safe }}, the point where a template's content is injected; safe means passed-in HTML renders as HTML rather than being encoded. The home page joins it by placing this front matter—dashes included—at the very top of index.md:
---
layout: base.njk
---
Checking the compiled HTML in public now shows the cat and dog loops inside the base.njk body. The same front matter goes on pets.njk, which gives layout chaining: content written in pets.njk is wrapped by the boilerplate in base.njk, so that HTML never has to be repeated.
A single pets.njk serves both cat and dog profiles by way of computed data, one of Eleventy's newer features. It assigns values from the cats and dogs datasets to the same template variables, avoiding if statements or two separate templates. The update below goes into cats.njk, with the dog equivalent substituting dog:
eleventyComputed:
title: "{{ cat.name }}"
petColor: "{{ cat.petColor }}"
favoriteFood: "{{ cat.favoriteFood }}"
favoriteToy: "{{ cat.favoriteToy }}"
photoURL: "{{ cat.photoURL }}"
ownerName: "{{ cat.ownerName }}"
ownerTwitter: "{{ cat.ownerTwitter }}"
eleventyComputed is the front matter key; it reaches into the dataset through the alias, so {{ title }} resolves a cat's name on cat pages and a dog's name on dog pages. The following in pets.njk loads whichever profile is being viewed:
<img src="{{ photoURL }}" />
<ul>
<li><strong>Name</strong>: {{ title }}</li>
<li><strong>Color</strong>: {{ petColor }}</li>
<li><strong>Favorite Food</strong>: {{ favoriteFood if favoriteFood else 'N/A' }}</li>
<li><strong>Favorite Toy</strong>: {{ favoriteToy if favoriteToy else 'N/A' }}</li>
{% if ownerTwitter %}
<li><strong>Owner</strong>: <a href="{{ ownerTwitter }}">{{ ownerName }}</a></li>
{% else %}
<li><strong>Owner</strong>: {{ ownerName }}</li>
{% endif %}
</ul>
Finally, add layout: pets.njk to the front matter of both cats.njk and dogs.njk.

Styling is out of scope here; the sample repository shows how CSS is included.
Deploying to Netlify
The site is functional enough to deploy. Netlify suits community-driven projects in particular: a deployment can be triggered when a submission is merged, and a preview of the submission can be viewed before it is sent for review. Connect a GitHub repo during Netlify's add-site flow, then specify public as the publish directory and npm run build as the build command, to run when changes merge to the main branch.
The sample project ships a netlify.toml holding the build details; Netlify detects it in the repo automatically, so the new-site flow doesn't need them. After the site is added, go to Settings → Build & deploy in Netlify, choose "Edit" under Deploy contexts, and set "Deploy Previews" to "Any pull request against your production branch / branch deploy branches." From then on every pull request gets a preview URL, linked directly in the pull request review screen.
The submission workflow and what comes next
Before opening the doors, revisit the first article's checklist: community health files should be in place, and a branch protection rule on the main branch is essential so your approval is required before any pull request merges. Contributors need a GitHub account; though that is a barrier, it also removes some anonymity, which can help vet contributors depending on the content's sensitivity or the audience. The flow is:
- Fork the website repository.
- Clone the fork locally, or use the GitHub web interface for the remaining steps.
- Create a unique
.jsonfile insrc/pets/catsorsrc/pets/dogscontaining the required data. - Commit on the clone, or save the file in the web interface.
- Open a pull request back to the main repository.
- Optional: check the Netlify deploy preview that information appears as expected.
- Merge the changes.
- Netlify deploys the new pet to the live site.
A FAQ is a good home for guidance on opening a pull request; Style Stage has an example.
Beyond this, Eleventy leaves room for extensions: Markdown files can carry the content of a Buttondown newsletter, mixing Nunjucks or Liquid with Markdown so a loop outputs the latest five pets as Markdown links; social preview images can be generated automatically; a commenting system can be added; and Netlify CMS Open Authoring can give submitters an interface instead of raw JSON. The Meow vs. BowWow example is available to fork on GitHub, with a live preview where pets can actually be submitted.



