-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
What problem does this address?
A convention was introduced as part of the web fonts feature, with regards to relative paths to theme assets in theme.json.
The convention is that a prefix of file:./
is required to indicate that a path is relative to the theme root directory.
For example, the following path —
"src": "file:./assets/some/file.ext"
— assumes that /assets/
is top-level directory of the theme.
This rule also applies to style variations, so theme.json files in the /styles
folder.
This convention was followed for background image URIs.
See the discussions in:
- Font Face: to generate and print font-face styles for theme.json fonts #51770 (comment)
- Background image: add support for relative theme path URLs in top-level theme.json styles #61271 (comment)
What is your proposed solution?
Relative paths using . as a prefix is misleading because the paths are actually relative to the theme directory and not to where the theme.json file is. It also implies that .. should work which it doesn't. We should make the paths actually relative or remove support for them. This is an issue for fonts as well.
I would propose either:
- Communicate that all paths, regardless of the depth, must be relative to the theme root, and perhaps also support
"file:"
(without dotslash to avoid confusion) by default and have backwards compat handling for"file:./"
- Allow paths that are relative to current directory, and then in resolve them in the background with PHP trickery with realpath or something.
As @creativecoder notes, we should update the docs to reflect the current behaviour:
For example:
The src property is unique in that it allows you to reference a URL that is relative to the theme's root directory, regardless of where the theme.json resides. For example, to reference a font bundled with your theme, you would use the "file:./path/to/file.ext" format in both the theme's main theme.json or in theme variation JSON files in the
/styles
directory.