Posted in Software Development tagged JavaScript

Ignoring Files with Eleventy

I love Eleventy, but I think I made a mistake in how I structure my sites. I don't consider blogs and other static sites the same way I think about coding projects. I don't toss everything inside of a src/ directory so my site content lives alongside files like README.md and I never thought much of it.

That was until the other day when I noticed one of my sites, that I openly utilize generative AI on, had my CLAUDE.md published for the world to see. The file itself lived at /CLAUDE/index.html on the open Internet, and I'm pretty sure nobody even noticed.

Side note, I was actually thinking of publishing this file for anybody that maybe wanted to run a similar site to leverage.

Anyway, not a big deal, no secrets leaked or anything like that. In fact, because I thought I had discovered some earth shattering thing, I went on a side quest, scanning over 1,000 sites advertising that they ran on Eleventy. I just knew I was going to expose a bunch of sites written by robots. I was going to be the John Connor of my generation.

Turns out I didn't find a single one. Maybe a bug in my scraper. I lost interest at some point, no big deal.

I ended up checking a few of my other sites, and definitely found I had a lot of README.md files out there, which I wanted to clean up next week. Also seems I have solved this issue on a few sites already. To take it a step further, I seem to have solved it a couple of different ways.

Eleventy Ignore File

Both methods are pretty easy, but I'd argue this is easiest. The file naming and the structure of it is very familiar.

Add a file named .eleventyignore in the root of your project, and add the files that you'd like to ignore, like README.md or TODO.md. When Eleventy builds, it'll ignore said files.

Eleventy Config

Also easy, and maybe preferred if you want everything in one place. Open up eleventy.config.js and inside of your default function add a line or lines like this:

export default function (eleventyConfig) {
  eleventyConfig.ignores.add('README.md');
  eleventyConfig.ignores.add('TODO.md');
  // Other stuff...
}

Same deal, when Eleventy builds, it'll ignore the files you listed out.

Ideal Fix

The better fix here would be to decouple my site content from the root of the project. Doing so will eliminate any need to ignore files. This reduces my cognitive load, and further simplifies my dumb little static site adventures.

But that's for another day.