wiki icon indicating copy to clipboard operation
wiki copied to clipboard

Added head and body injection to editor template.

Open Morgul opened this issue 2 years ago • 3 comments

I've added head and body injection to the editor template, so that the preview for the page shows custom web components / page extensions that have been injected into the extra head / extra body portion of the settings.

Use Case

Since there isn't currently any kind of plugin or extension system, I decided to write some custom html components (i.e. images with captions/details sections, custom symbols for rpg dice results, etc) to wrap up what was turning into a bit of a nightmare of custom style + copy/pasting boilerplate html all over the place. Using web components turned out to be really easy, as I just have to add a .css and .js file into the head of my wiki, and then the custom components work great (especially the shadow dom style encapsulation). Except, none of the custom markup renders in the preview.

The fix seemed simple enough, and adds a very nice vector for extending wiki.js, imho.

Questions

  • Are there any concerns with this? I couldn't really think of any that wouldn't be obvious and fixable?
  • Should we also add this to pages like history/admin?
  • Should, maybe, this be a set of options where you can turn on/off which page templates get this injection? (That feels like overkill, imho.)

Morgul avatar May 30 '22 22:05 Morgul

The reason the code injection is not included in editor/admin pages is because there's a risk of completely bricking the page if user code does something unexpected. Then you have absolutely no way to edit the page because the editor is broken as well.

So this "feature" would definitely need to be optional and off by default.

NGPixel avatar May 30 '22 22:05 NGPixel

Thanks

Itimol82 avatar May 31 '22 09:05 Itimol82

Would something along the lines of this be acceptable?

image

(I'm still working out how to extend the config model correctly to make the button work, but figured I'd at least mock it up.)

Morgul avatar Jun 03 '22 22:06 Morgul