2

Is it possible somehow to do a general configuration for Eleventy so that 'my_file.html' in the input folder ends up just as 'my_file.html' in the _site folder, not '/my_file/index.html'?

I know I can do it on a file by file basis with permalinks. But I'd like it configured for the site as a whole, if possible.

John Moore
  • 6,739
  • 14
  • 51
  • 67

2 Answers2

6

Unfortunately, since this behavior isn't encouraged, there isn't a simple configuration option to disable the directory output.

However, since permalink is part of the data cascade, you can set a global default, and in combination with the filePathStem computed data, you can set the output to be .html files.

To set a permalink using a global data file, add a permalink.js file to your global _data directory.

// _data/permalink.js
module.exports = '/{{ page.filePathStem }}.html'

There is also a config global data option coming soon to v1.0.0. I am not sure if it will handle the {{ page.filePathStep }} preprocessing, but if it does, that could be an option too, especially since it will keep config-related things inside the config file.

person_v1.32
  • 2,641
  • 1
  • 14
  • 27
  • 3
    Great answer! Just a big warning that `permalink` strings will be processed to the syntax of the template file, so using a string globally might be a bit iffy. Should be safer to use a function instead. – zachleat May 27 '21 at 16:38
1

Yes, you can control where Eleventy writes things out by specifying a permalink value in the front matter. This is covered here: https://www.11ty.dev/docs/permalinks/#remapping-output-(permalink)

An example would be:

---
permalink: "/my_file.html"
---
Raymond Camden
  • 10,661
  • 3
  • 34
  • 68