Open matiasbenedetto opened 11 months ago
- Add the fonts activated with the font library to the exported theme zip.
- Set the right font asset source in theme.json
I am not sure if we should do this. I think my preference is to enhance Create Block Theme to handle it: https://github.com/WordPress/create-block-theme/issues/451.
Font Library is designed so that installed fonts are treated more like Media and are theme agnostic — hence the default install location is in wp-content/fonts
, not in the theme assets. To make the theme export work with fonts across sites, we'd have to move the fonts inside the theme, and then overwrite each font face's src property with a relative file path in theme.json. This would mean adding some typography specific processing of theme.json, to the current export functionality. There's no precedence for this.
Also a font face src can be a remote host — how would we know when to move the font to the theme assets and rewrite the src, vs leaving the src untouched? We could perform a string comparison to see if the src contains the domain of the current site, and do a replacement with file:/
, but that also doesn't seem ideal for the native export functionality which is currently just a dump of the existing templates and styles.
I think it's good to bring up the Media Library, I do think it's related.
Patterns are an integral part of a theme and the patterns that are created in the Site Editor reference assets in the Media Library. Whatever fate befalls the fonts will also befall this media: Either it will be exported with a theme or it won't. You're right in that the assets are managed in the same way.
Ultimately, CBT will be complete when Core/Gutenberg does all the things and CBT can be sunset. Part of that goal is that when a theme is exported the relevant media elements are exported too. If we do it in CBT it is bound for Core anyway. Doing it now will help inform how other relevant media assets are exported and this seems a simple thing to implement and a good time to do it. However if it's better to defer this and experiment to get it right then I hope we can still target the same timeline, wherever the code changes happen.
Regarding fonts from remote hosts, I think that in all instances the result should be the same. A font stored in the theme.zip file and referenced locally. However it's stored in the instance.
Doing it now will help inform how other relevant media assets are exported and this seems a simple thing to implement and a good time to do it.
👍
WordPress has been lacking in export features for a long time, and this issue with fonts seems to fall right in line with that problem. At the end of the day, if I export a theme, I want everything that's a part of that theme in the export, including media that's part of patterns and any fonts I use in the templates and styles.
For me, the question is simply how to implement better export functionality. I think experimenting with font export in Gutenberg's theme zip would be a useful starting point to lead the way.
I am not sure if we should do this. I think my preference is to enhance Create Block Theme to handle it
I understand why adding this functionality to Create Block Theme may currently feel like the better approach, considering the limited export features currently in WordPress. I'm mainly echoing what's been said above, but I think the new Font Library is a good opportunity to expand the current export features and explore what the next iteration of this functionality looks like in Core.
I think we would need to implement this on the core at some point. Otherwise, the theme exported by the 'Export' core functionality would be incomplete, right?
We could handle the fonts this way:
As a more general comment, all the Export functionality is lacking behind the capabilities implemented on the Create Block Theme plugin; at some point, we should try to move the newer functionality around exporting a theme and testing well in CBT to core.
I un-assigned myself, since I will not finish this before my extended leave. The above PR is a good place to start I think.
What?