From 0168f8e5ac0e90549f92fc1512bea95a2ac3fa14 Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Fri, 27 Aug 2021 13:33:51 -0400 Subject: Fix TOC rendering issues While rendering TOC, some items were lost. For example: - if last h1 has some children or grand children - if any h1 has multiple h2 (without any h3) Signed-off-by: Khosrow Moossavi --- exampleSite/content/errors.md | 6 ++++++ layouts/partials/funcs/toc_from_pages.html | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/exampleSite/content/errors.md b/exampleSite/content/errors.md index db7949e..9cbfdee 100644 --- a/exampleSite/content/errors.md +++ b/exampleSite/content/errors.md @@ -10,6 +10,7 @@ title: Errors The Kittn API uses the following error codes: +## 4xx Error Code | Meaning ---------- | ------- @@ -22,5 +23,10 @@ Error Code | Meaning 410 | Gone -- The kitten requested has been removed from our servers 418 | I'm a teapot 429 | Too Many Requests -- You're requesting too many kittens! Slow down! + +## 5xx + +Error Code | Meaning +---------- | ------- 500 | Internal Server Error -- We had a problem with our server. Try again later. 503 | Service Unavailable -- We're temporarially offline for maintanance. Please try again later. diff --git a/layouts/partials/funcs/toc_from_pages.html b/layouts/partials/funcs/toc_from_pages.html index 1317b74..456f8a6 100644 --- a/layouts/partials/funcs/toc_from_pages.html +++ b/layouts/partials/funcs/toc_from_pages.html @@ -40,6 +40,9 @@ {{ $h2s = $h2s | append $tocItem }} {{ $h3s = slice }} {{ end }} + {{ if eq $previousLevel 2 }} + {{ $h2s = $h2s | append $previousH2 }} + {{ end }} {{ $previousH2 = $item }} {{ else }} {{ $h3s = $h3s | append $item }} @@ -50,6 +53,9 @@ {{ end }} {{ if ne $previousLevel 0 }} + {{ $tocItem := merge $previousH2 (dict "sub" $h3s) }} + {{ $h2s = $h2s | append $tocItem }} + {{ $item := merge $previousH1 (dict "sub" $h2s) }} {{ $toc = $toc | append $item }} {{ end }} -- cgit v1.2.3