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?