Skip to content

Conversation

@clarfonthey
Copy link
Contributor

Problems:

  • Absolute paths are always relative to the system root. So, for example, /file doesn't mean the file in options.root, but /file on the system.
  • Paths aren't relative to individual files. For example, in folder/file.html and folder/child/file.html, with root set to folder, the path file.txt is always folder/file.txt instead of folder/child/file.txt for the second.

Solution:

  • The existing options.root is only applied to absolute paths.
  • Introduce a separate options.cwd parameter which corresponds to the former options.root.
  • Fall back to using the from path from posthtml is cwd is unset, only defaulting to the current directory if that isn't set.

Notes:

  • This is a breaking change, but I can't imagine a way of making this that wouldn't be breaking. We could make root really be cwd and give some other name for root, but this would be too confusing imho.

@Scrum
Copy link
Member

Scrum commented Oct 21, 2022

@clarfonthey What is stopping you from passing in the process.cwd() parameter?

@clarfonthey
Copy link
Contributor Author

clarfonthey commented Nov 2, 2022

@Scrum Defaulting to process.cwd is a rather minor part of this change; the main purpose is to differentiate /absolute/paths and relative/paths such that the former is always relative to options.root, whereas the latter is relative to a new option, options.cwd.

Compare this to the current implementation, where /absolute/paths correspond to absolute paths on the system executing the code (not very useful, unless I want to <include src="/etc/profile"> or something), and relative/paths are always treated like the /absolute/paths as mentioned above.

@jeremysawesome
Copy link

Seemingly related issue #94

@Scrum Scrum merged commit 43d9f3c into posthtml:master Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relative Includes Should be Relative to the HTML File the Include is In Relative imports not working

3 participants