How to omit specific heading from TOC?

I have a separate heading at end of my post for Further reading, which I don’t want to show up in the TOC.

The heading is normally defined with markdown as level 4 heading

#### Further reading

content...

Presently, the heading shows up in my TOC normally like other headings. I don’t expect that behaviour since my TOC template code is supposed to show only 2 levels of headings. (I might be wrong with this part)

In LaTeX, I can omit a specific heading from TOC by using aesterix (eg \section*{Further reading})

Is something similar possible with Zola?

TOC template code from page.html
{% if page.toc %}
<a onclick="toggle('toc-custom')">Toggle table of contents</a>
<div id="toc-custom" style="display:none">
<h3>Contents</h3>
<ul>
{% for h1 in page.toc %}
    <li>
        <a href="{{ h1.permalink | safe }}">{{ h1.title }}</a>
        {% if h1.children %}
            <ul>
                {% for h2 in h1.children %}
                    <li>
                        <a href="{{ h2.permalink | safe }}">{{ h2.title }}</a>
                    </li>
                {% endfor %}
            </ul>
        {% endif %}
    </li>
{% endfor %}
</ul>
</div>
<hr>
{% endif %}

Playing around, I discover that using HTML doesn’t show up the heading in TOC.

<h4>Further reading</h4>

Not sure if this is the way Zola intends this to be achieved though.

It’s not about their actual HTML tag, but rather their level. So you can’t just add more # to hide a heading. If your Further Reading section were nested within two levels, then it would be hidden.

Regarding your actual question, yes, it’s possible, with a bit of work.

For my theme, I wrote a table of contents macro that checks for an “ignore pattern”. See the code here.

Basically, before rendering a heading, it checks if it matches a Regex set at the page level, on the post’s front matter.

For your specific use case, you’d set the ignore pattern like:

+++
title = "Your Post's Title"
date = 2023-10-02

[extra]
toc_ignore_pattern = "^(Further reading)"
+++

Hope that helps!