I want to enable ToC on both page
and post
layouts. Here’s the modified template I am using.
I have tried with changing the _layouts/page.html in the following way:
---
layout: default
refactor: true
panel_includes:
- toc
---
{% include lang.html %}
{% include toc-status.html %}
<article class="px-1" data-toc="{{ enable_toc }}">
{% if page.layout == 'page' or page.collection == 'pages' %}
{% assign page_key = page.title | downcase %}
{% assign title = site.data.locales[lang].pages[page_key] | default: page.title %}
<header>
<h1>
{{ title }}
</h1>
{% if page.description %}
<blockquote class="prompt-info">{{ page.description }}</blockquote>
{% endif %}
</header>
{% if enable_toc %}
<div id="toc-bar" class="d-flex align-items-center justify-content-between invisible">
<span class="label text-truncate">{{ page.title }}</span>
<button type="button" class="toc-trigger btn me-1">
<i class="fa-solid fa-list-ul fa-fw"></i>
</button>
</div>
<button id="toc-solo-trigger" type="button" class="toc-trigger btn btn-outline-secondary btn-sm">
<span class="label ps-2 pe-1">{{- site.data.locales[lang].panel.toc -}}</span>
<i class="fa-solid fa-angle-right fa-fw"></i>
</button>
<dialog id="toc-popup" class="p-0">
<div class="header d-flex flex-row align-items-center justify-content-between">
<div class="label text-truncate py-2 ms-4">{{- page.title -}}</div>
<button id="toc-popup-close" type="button" class="btn mx-1 my-1 opacity-75">
<i class="fas fa-close"></i>
</button>
</div>
<div id="toc-popup-content" class="px-4 py-3 pb-4"></div>
</dialog>
{% endif %}
<div class="content" style="text-align: justify;">
{{ content }}
</div>
{% else %}
{{ content }}
{% endif %}
<!-- lastmod date -->
<!-- pageviews -->
</article>
and tested with following change in _pages/about.md:
---
layout: page
title: About
permalink: /about/
toc: true
---
# H1
## H2
### H3
The ToC is not appearing. How to resolve it?