Skip to content

How can I define arbitrary markdown template as index of parent folder? #3067

Answered by pdehaan
asterixpound asked this question in Q&A
Discussion options

You must be logged in to vote

Would a directory data file w/ computed permalink work?

// 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…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@asterixpound
Comment options

@pdehaan
Comment options

pdehaan Oct 11, 2023
Collaborator

@asterixpound
Comment options

Answer selected by asterixpound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants