In a Discourse Dev category thread titled “TypeError: Discourse.Dialect.postProcessText is not a function,” user DanielMarquard sought help while developing a plugin. Initially, they encountered an error because the postProcessText function was deprecated. User cpradio provided a corrected code snippet using the new pretty-text API and registerOption, advising the removal of obsolete register_asset lines cpradio. They further assisted by adding necessary CSS whitelisting for specific Overwatch hero classes, resulting in a working plugin cpradio.
Subsequently, DanielMarquard raised a new issue regarding font assets. The plugin’s fonts were not accessible when the site was installed in a subdirectory, as register_asset does not support font files cpradio. After searching the file system, DanielMarquard confirmed that while fonts existed in the plugin directory, they were not served correctly DanielMarquard. cpradio suggested three potential solutions: hosting fonts on a CDN, uploading them to the site root, or instructing users to manually upload them via Site Settings cpradio. Ultimately, DanielMarquard decided to host the fonts on GitHub and update the stylesheet URLs, thanking cpradio for the extensive assistance DanielMarquard.
I knew this was probably going to be an issue, but couldn’t find any resources for circumventing it. The fonts are registered as assets, then referenced in the stylesheet as relative URLs. This is a problem for our website, and will be for other Discourse websites accessed in a directory (i.e., https://critcola.com/community/).
Of course, I could easily fix this for us, but then the plugin would be unusable by other Overwatch communities. Any thoughts on how to approach this?
As I think it is relative to the Stylesheet path, and thus the font folder will be up one directory which will also be true for non-subfolder installs.
I didn’t even think of that. I think we’re getting closer. Since I knew the first approach I took wouldn’t work, I didn’t even bother to check if the fonts were actually there, but now that I updated the font paths using your relative URL scheme, I’m seeing that the fonts don’t appear to be there.
There are fonts for Font Awesome in Discourse’s assets directory, but no actual “fonts” directory, as far as I can tell. A search for fonts in Discourse’s filesystem found the fonts in the plugin’s directory, but not somewhere where it would be Internet-accessible, I think. Any idea why? Where should fonts registered as assets in the plugin be stored?
Okay, so it works locally (or in a dev) environment because you don’t have to use register_asset to get to it. The issue you are going to have is register_asset doesn’t accept font files.
So the best solution I can give you, is one of the following
Upload the fonts to a CDN, reference the CDN in the CSS (applies for all scenarios).
Upload the fonts to the root of your main site and in the CSS use /fonts/overwatch-heroes…
Inform people in the README to do the same so it works for them too (doesn’t really apply for those running on a sub-domain though)
Instruct users to change the Site Setting authorized extensions to be able to upload the fonts, then copy and paste CSS into the Admin > Customize area to reference those uploaded URLs for the @font-face (and in your plugin CSS, do not have that @font-face portion in it)
This is probably the most convoluted way
So without getting the fonts to a location where they can be served, you won’t be able to reference them
Strange. Last night, I ended up hosting the fonts with GitHub and changing the font URLs in the stylesheet, so I’ll probably stick with that approach. I wonder why fonts are restricted in plugins?