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:

[extra]
katex_enable = true

while DeepThought does:

# Enable external libraries
[extra]
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
like

<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!

I don’t it’s possible to share features like that. Everyone might want to do things differently/load from a CDN and the look will change depending on the theme so it will also need to include some CSS.

Well, that even and deepthought do it in the same way suggests that not everyone will want to do things differently. And, yes, there might need to be styling. Maybe there would be a way to achieve that, but if macros and shortcodes were shared then the styling would remain where it is now; in the theme.

1 Like

I agree there is a need to share some features, but maybe not the ones directly linked to the theme. I rather think about a way to share macros and shortcodes (and I’m not sure why we wouldn’t merge these concepts, shortcodes are just a kind of macro that accept their content as a multiline argument).

Maybe we could create a thread on this forum to share them. One per post, with minimal documentation. Or maybe an independent git repo… I will think about that.

1 Like