Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralized directory references for input/output/layouts/data/includes, changes Virtual Templates to be input dir relative. #3244

Merged
merged 15 commits into from Apr 8, 2024

Conversation

zachleat
Copy link
Member

@zachleat zachleat commented Apr 6, 2024

Preparation for #67 and #1503 and #2307.
Assisting on #1612 (making virtual template paths relative to input dir).

The biggest practical change here is that you’ll be able to reference Eleventy’s full resolved directories in plugins and configuration files. This will include values set via command line arguments #2729.

Command Line

However, if you pass --input or --output directories in on the command line, the values will be correct #2729, e.g. npx @11ty/eleventy --input=content:

export default function(eleventyConfig) {
  eleventyConfig.directories.input; // has "./content/"
};

When returning dir in your config:

This works as expected with plugins. Use addPlugin to get the correct values (plugins run in a second stage).

export default function(eleventyConfig) {
  // Plugins run in a second stage, so we have access to the return object data below
  eleventyConfig.addPlugin(eleventyConfig => {
    // These values always have a trailing slash (if directory); always posix-style forward-slash paths
    eleventyConfig.directories.input; // has "./content/"
    eleventyConfig.directories.output; // has "./_site/"

    // includes, data, layouts directories (input dir relative) are normalized to project root relative.
    eleventyConfig.directories.includes; // has "./content/_includes/
    eleventyConfig.directories.layouts; // is falsy (not specified)
    eleventyConfig.directories.data; // has "./content/_data/"
  });

  return {
    dir: {
      input: "content",
      includes: "_includes",
      data: "_data",
      output: "_site",
    }
  }
};

If you don’t use addPlugin, you’ll get the wrong values. (Fixed with new config export #3246)

export default function(eleventyConfig) {
  // WARNING: this will be wrong if you return an object in your config file
  eleventyConfig.directories.input; // has "./"

  return {
    dir: {
      input: "content",
      includes: "_includes",
      data: "_data",
      output: "_site",
    }
  }
};

@zachleat zachleat added this to the Eleventy 3.0.0 milestone Apr 6, 2024
@zachleat zachleat changed the title Centralized directory references for input/output/layouts/data/includes In progress: centralized directory references for input/output/layouts/data/includes Apr 6, 2024
@zachleat zachleat marked this pull request as draft April 6, 2024 04:36
@Zearin
Copy link
Contributor

Zearin commented Apr 6, 2024

Ooh, cool! :D

I especially love the simplified constructors! 🥳

@zachleat zachleat marked this pull request as ready for review April 8, 2024 14:00
@zachleat zachleat changed the title In progress: centralized directory references for input/output/layouts/data/includes Centralized directory references for input/output/layouts/data/includes, changes Virtual Templates to be input dir relative. Apr 8, 2024
@zachleat zachleat merged commit 6deb016 into main Apr 8, 2024
6 checks passed
@zachleat zachleat deleted the directory-normalization branch April 8, 2024 15:46
@zachleat
Copy link
Member Author

zachleat commented Apr 8, 2024

Shipping with 3.0.0-alpha.6

@zachleat
Copy link
Member Author

zachleat commented Apr 19, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature: 🛠 configuration Related to Eleventy’s Configuration file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants