Eleventy: Can Eleventy globally transform all input files with a given name to a different output name WITHOUT dir data files?

Created on 26 Aug 2020  路  3Comments  路  Source: 11ty/eleventy

Given an input of:

README.md
  - dir1/
    - README.md
    - anotherfile.md
  - dir2/
    - README.md

is there a GLOBAL option that I can use to have README.md files output as index.html?

THE HUGE CATCHES are:

  • For reasons of tidyness and non-tech people being involved I don't want data files like readme.11tydata.js in the same directory as the markdown files.
  • the markdown files can't contain frontmatter.

Is this possible?

Example: https://github.com/springernature/diversity-hiring. I'd like the root to be cleared of the data file (and .eleventyignore if it's possible to configure that away also)

education

Most helpful comment

an alternative solution, right in the eleventy file:

eleventyConfig.addCollection('readme', collection => {
    return collection.getAllSorted().map(item => {
        if (item.fileSlug === 'README') {
            item.outputPath = item.outputPath.replace('/README', '');
        }
    });
});

output:

Writing _site/index.html from ./src/README.md.
Writing _site/dir2/index.html from ./src/dir2/README.md.
Writing _site/dir1/anotherFile/index.html from ./src/dir1/anotherFile.md.
Writing _site/dir1/index.html from ./src/dir1/README.md.
Wrote 4 files in 0.21 seconds (v0.11.0)

All 3 comments

LOOK AT THIS LOVELY BOY AND HIS SOLUTION!: https://twitter.com/zachleat/status/1298641013968437251

I should be able to use eleventyComputed.js to transform the page.inputPath value.

馃榿

an alternative solution, right in the eleventy file:

eleventyConfig.addCollection('readme', collection => {
    return collection.getAllSorted().map(item => {
        if (item.fileSlug === 'README') {
            item.outputPath = item.outputPath.replace('/README', '');
        }
    });
});

output:

Writing _site/index.html from ./src/README.md.
Writing _site/dir2/index.html from ./src/dir2/README.md.
Writing _site/dir1/anotherFile/index.html from ./src/dir1/anotherFile.md.
Writing _site/dir1/index.html from ./src/dir1/README.md.
Wrote 4 files in 0.21 seconds (v0.11.0)

I ended up using @vfalconi's solution. Thanks for the help, folks!

Was this page helpful?
0 / 5 - 0 ratings