Sharing Features in Addition to Themes

I notice that quite a lot of the themes add some fairly
significant functionality to the generated websites. Common examples
include katex or mathjax functionality, open graph or equivalent
metadata, and dark mode (either server or client side) switches.

Some of this functionality is pretty nice, but in a theme, it’s also
tied up with the visualisation and appearance of the content. Some of
themes come with quite a lot of configuration. And the details can
vary between themes.

For example, considering katex. The even theme does this:

katex_enable = true

while DeepThought does:

# Enable external libraries
katex.enabled = true
katex.auto_render = true

Obviously this means, it is not possible to move between even and
deepthought without reconfiguring. Fortunately, contentwise, both of
them share the same user interface, that is to use a short code.

{{ katex(body="\KaTeX") }}

Although the implementation is similar but different. So even looks

<script type="math/tex{% if block %};mode=display{% endif %}">{{body | safe}}</script>

while, DeepThought misses the safe but is otherwise identical.

<script type="math/tex{% if block %};mode=display{% endif %}">{{body}}</script>

So, the content probably wouldn’t need changing to move between
themes, although there are probably some cases where it doesn’t work
exactly the same.

I know that in HTML it is difficult to split function and
appearance. Even in website frameworks like Wordpress, which split
things into plugins and themes, it does not quite work. Some themes
add a very large amount of plugin-like functionality. And many plugins
only work with some themes.

But I wonder is there a good way of sharing this kind of functionality
between Zola themes. Or, indeed, incorporating it into a site not
using a theme. How could, for example, the (nearly) code duplication
be factored out into a generic “katex” implementation?

I guess it was adding some thoughts here that might enable this as I don’t think Zola can support it at the moment.

Would it be enough to support a mechanism like current themes but only allows tera macros and short codes to be shared. Might call these “plugins” but would otherwise work like themes. They could be a standard zola project (so would carry their own documentation). They could be cloned into a plugins directory which would them. Unlike themes, you could enable multiple of them at one time. To fulfil the functionality required here, you’d need to be able to put plugins inside themes (so even and DeepThought could both pull in the katex plugin). I guess this takes you down the git submodule route.

Anyway this is just a strawman. There might be a better way that a) I haven’t thought of and b) already exists!