How can I define arbitrary markdown template as index of parent folder? #3067
-
Given a folder in my input directory, I would like to be able to specify one of the markdown templates it contains as its index without having to name that file One way of achieving this is by setting I would think there would be a way to use Eleventy's supplied data to get the input path of the folder containing An alternative possibility I have wondered about is whether I could take advantage of the naming convention I use for those markdown templates which correspond to an index. In particular, I always start the name of these files with an underscore. None of my other markdown templates have names starting with an underscore. Would it be possible to create a rule which always maps |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Would a directory data file w/ computed // src/path/path.11tydata.js
const path = require("node:path");
module.exports = {
permalink(data) {
if (data.index) {
// console.log("We got an index page here!", data.page);
const parent = path.resolve(data.page.filePathStem, "..");
return path.join(parent, "index.html");
}
return data.url;
}
} ---
# src/path/to/foo.md
title: Foo
index: true
---
<h1>{{ title }}</h1>
<pre>
{{ page | json: 2 }}
</pre> eleventy
[11ty] Writing www/path/to/index.html from ./src/path/to/foo.md (liquid)
[11ty] Writing www/path/to/bar/index.html from ./src/path/to/bar.md (liquid)
[11ty] Wrote 2 files in 0.04 seconds (v2.0.1) <!-- www/path/to/index.html -->
<h1>Foo</h1>
<pre>
{
"date": "2023-10-11T00:25:06.036Z",
"inputPath": "./src/path/to/foo.md",
"fileSlug": "foo",
"filePathStem": "/path/to/foo",
"outputFileExtension": "html",
"templateSyntax": "liquid,md",
"url": "/path/to/",
"outputPath": "www/path/to/index.html"
}
</pre> |
Beta Was this translation helpful? Give feedback.
Would a directory data file w/ computed
permalink
work?eleventy [11ty] Writing www/path/to/index.html from ./src/path/to/foo.md (liquid) [11ty] Writing www/path/to/bar/index.html from ./src/path/to/bar.md (liquid) [11ty] Wrote 2 files in 0.04 seconds (v2…