[gi-docgen/ebassi/content-toc-update] generate: Improve the TOC for content files
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gi-docgen/ebassi/content-toc-update] generate: Improve the TOC for content files
- Date: Tue, 25 Jan 2022 13:39:30 +0000 (UTC)
commit 045e76af2928ea20e31d841a6b1d22d4bf8e5ad3
Author: Emmanuele Bassi <ebassi gnome org>
Date: Tue Jan 25 13:37:42 2022 +0000
generate: Improve the TOC for content files
We can omit level 1 headings if there's only one of them, as it usually
means the title of the document; we should always show level 2 headings,
as they are more common in all cases.
gidocgen/templates/basic/content.html | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/gidocgen/templates/basic/content.html b/gidocgen/templates/basic/content.html
index a8268ef..70d4979 100644
--- a/gidocgen/templates/basic/content.html
+++ b/gidocgen/templates/basic/content.html
@@ -31,9 +31,22 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
<nav aria-labelledby="toc-title">
<p id="toc-title">Content</p>
<ul class="toc-list">
- {% for header in content.toc %}
- <li class="toc-list-item"><a href="#{{ header.id }}"><span class="link-text">{{ header.name
}}</span></a></li>
- {% endfor %}
+ {% if content.toc|length == 1 %}
+ {% for subheader in content.toc[0].children %}
+ <li class="toc-list-item"><a href="#{{ subheader.id }}"><span class="link-text">{{ subheader.name
}}</span></a></li>
+ {% endfor %}
+ {% else %}
+ {% for header in content.toc %}
+ <li class="toc-list-item"><a href="#{{ header.id }}"><span class="link-text">{{ header.name
}}</span></a></li>
+ {% if header.children %}
+ <ul class="toc-list">
+ {% for subheader in header.children %}
+ <li class="toc-list-item"><a href="#{{ subheader.id }}"><span class="link-text">{{
subheader.name }}</span></a></li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ {% endfor %}
+ {% endif %}
</ul>
</nav>
</div>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]