-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
RFC: Eleventy’s directories should always be root-relative #232
Comments
I've struggled with the default setup / directory structure and think the discussion is wider than #67. It might be worth reopening for a general thread on directory structure. Off hand, it also relates to #229 and #228. Possibly also #214 which confused me. Edit: Like you, my view is that most things should be repo-root relative. I'd prefer to keep assets, templates, content (posts), data all in their own folders at the same level. At the moment some have to be one level deeper due to what Eleventy considers 'input'. I'd then expect most config things ( It's a breaking change, but I think the current setup is likely to cause others to trip up in the future. |
I agree; would love to be able to (optionally) define all paths explicitly relative to the repo root. Maybe just check for root-relative paths in
Which would work for:
Maybe also worth considering: allow multiple
|
I don’t think a leading slash should be used to stand for Eleventy’s root directory. On an operating system-level, the slash usually represents the root directory of the file system. I don’t think it’s necessary to borrow the slash for a different concept here. |
What about a true/false toggle ? Something like the following in {
...
dir:{
...
evaluateFromRoot: false //this will be false by default
}
...
} |
I don’t want this to be configurable. In my opinion, there should be one clear way how Eleventy handles its special directories eventually. |
Strong agree. If we can avoid adding complexity, we should. Might be a breaking change, but that's why projects use semver. |
And as shown in the original post, the change can be introduced incrementally to ensure as little breakage as possible. |
👍 for having all directories be root-relative. Personally, I wouldn’t be too concerned if this was a breaking change, as long as versioning and documentation sufficiently highlighted that fact. After all, this change should only require updating a few lines in the config file. |
Not quite. In content and/or data files, either the references to layout templates would need to be updated or the location of the layout templates needs to be moved accordingly. |
Are references to layout templates not relative to the includes directory? Of course there could be files outside the remit of 11ty that may need updating (styles, scripts etc.), but I thought anything relating to 11ty shouldn’t be effected once paths in the configuration file had been updated. |
@paulrobertlloyd Indeed, they are. What I wrote above is wrong. Maybe I had something different in mind, but I can’t think of it right now. |
While trying to configure my folder structure I came across some odd behavior. I can use "../../theme" as my include path but if I use "../../data" as my data path it never loads the data. So it appears that include allows for parent directory paths and the data property does not. This leads me to believe that if both supported "../" then it would be possible to move your data and include folders to the root. Does that sound correct? Also, can anyone explain the different behaviors? Thanks! |
Err.. my bad. After further debugging I found that the ../data path works but it assigns it to a different name:
This makes sense, I just had not thought about it. So for me this solves the problem of folder structure though it is certainly not the cleanest solution. |
TL;DR: Should Eleventy’s includes and data directories be relative to the input directory (i.e.
dir.input
) or to the project root?References:
includes
dir is relative to current dir orinput
dir #67 Check ifincludes
dir is relative to current dir orinput
dir.gitignore
and.eleventyignore
files #229 Default location of.gitignore
and.eleventyignore
filesBackground
Currently, the directories
dir.includes
anddir.data
are relative todir.input
.In my opinion, this overcomplicates matters. I’m not able to include files from arbitrary directories. Examples:
dir.input/css
. Currently, this requires either moving/css
intodir.input/dir.includes
or making the includes directory the same as the input directory by settingdir.includes
to""
.dir.input/dir.includes
.I want to hear some use cases for nesting the directories like this. I’m opinionated towards one side here, obviously, so I’m likely to miss advantages of the current behavior. Please help me gather some advantages and disadvantages.
Compatibility
Changing the current behavior would be a huge breaking change. Simply switching the default behavior is not possible at this point.
If this behavior should ever be changed, the transitioning period could be implemented by assigning priorities to the different evaluation behaviors. An example:
Project file structure:
.eleventy.js
:Path evaluation algorithm:
Let
eleventyDirectoryPath
be the directory to evaluate.Does
eleventyDirectoryPath
exist indir.input
?If yes, append
eleventyDirectoryPath
todir.input
. Done.Does
eleventyDirectoryPath
exist in the project root directory?If yes, append
eleventyDirectoryPath
to the project root directory. Done.If no, throw an error.
eleventyDirectoryPath
is invalid.Example:
dir.includes
:eleventyDirectoryPath
is set to_includes
._includes
exists withinproject-root/src
.dir.includes
will be computed asproject-root/src/_includes
. Done.dir.data
:eleventyDirectoryPath
is set to_data
._data
does not exist withinproject-root/src
._data
exists withinproject-root
.dir.data
will be computed asproject-root/src/_data
. Done.This would allow users to opt-in to the new behavior without breaking the default behavior for existing users. If the current behavior should ever be deprecated, the priority can be reversed as a second transition step, effectively making the current behavior an opt-in feature.
The text was updated successfully, but these errors were encountered: