Routing
Routing is handled by Eleventy and is file-based by default, meaning that URLs are composed of the subdirectory path to each individual document.
This documentation assumes the following:
config.baseUrlis set to"/", meaning that the site is served from root- the project's
config.dir.inputinput path is set to/docs, which is the default - the project's
config.dir.outputoutput path is set to/_site, which is the default
./docs/path/to/document.md --> ./_site/path/to/document/index.html
Eleventy writes every document to its own subdirectory as index.html, which has several advantages:
- Servers usually serve a file called
index.htmlfrom any subdirectory that fits the requested URL, meaning that there are no further server settings to be made. - This approach allows for both, requests that include a trailing slash (which is standard-conform) and those, that don't.
Implicit Routing
As stated above, Eleventy supports file-based routing by default. This means that the input directory's structure is more or less copied into the output directory. There is no need to manually set output paths for each page.
An example input directory might look something like this:
.
└─ /docs
├─ /guide
│ ├─ doc-1.md -> /guide/doc-1/index.html
│ └─ doc-2.md -> /guide/doc-2/index.html
└─ /reference
├─ doc-3.md -> /reference/doc-3/index.html
└─ doc-4.md -> /reference/doc-4/index.html
For an elaborate example, see this very documentation's source!
Permalinks
To overwrite this behavior, LFP Docs offers a special permalink frontmatter key, where you can set an arbitrary path for a file (it must be unique!). Learn more at the frontmatter reference and Eleventy's permalink documentation.
While it is possible to manually set individual links for each page, regardless of directory structure, it is strongly advised to largely rely on file-based-routing for organizing source files.