From eea712d4d11c34a83f8534f963d0c956fa1e6d0a Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Sun, 8 Mar 2026 08:48:37 +0100 Subject: [PATCH] Show article TOC below author in post sidebar --- _includes/components/blog-sidebar.njk | 35 ++++++++++++++++ _includes/components/widgets/toc.njk | 44 +++++++++++++++++++- theme/_includes/components/blog-sidebar.njk | 35 ++++++++++++++++ theme/_includes/components/widgets/toc.njk | 46 +++++++++++++++++++-- 4 files changed, 155 insertions(+), 5 deletions(-) diff --git a/_includes/components/blog-sidebar.njk b/_includes/components/blog-sidebar.njk index 54bde2e..fc73460 100644 --- a/_includes/components/blog-sidebar.njk +++ b/_includes/components/blog-sidebar.njk @@ -3,8 +3,12 @@ {# Each widget is wrapped in a collapsible container with localStorage persistence #} {% from "components/icon.njk" import icon %} +{% set isArticlePost = (postType == "article") or (page.url and page.url.startsWith('/articles/') and page.url != '/articles/') %} +{% set showArticleToc = isArticlePost %} + {% if homepageConfig and homepageConfig.blogPostSidebar and homepageConfig.blogPostSidebar.length %} {# === Data-driven mode: render configured widgets === #} + {% set hasConfiguredToc = '"toc"' in (homepageConfig.blogPostSidebar | dump) %} {% for widget in homepageConfig.blogPostSidebar %} {# Resolve widget title #} @@ -160,6 +164,21 @@ + {% if showArticleToc and not hasConfiguredToc and (widget.type == "author-card" or widget.type == "author-card-compact") %} + {% set widgetKey = "post-widget-toc-article" %} +
+
+ +
+ {% include "components/widgets/toc.njk" %} +
+
+
+ {% endif %} + {% endfor %} {% else %} {# === Fallback: aligned with rmendes.net article sidebar === #} @@ -178,6 +197,22 @@ + {% if showArticleToc %} + {# Table of Contents (articles only) #} + {% set widgetKey = "post-widget-toc-article" %} +
+
+ +
+ {% include "components/widgets/toc.njk" %} +
+
+
+ {% endif %} + {# Share #} {% set widgetKey = "post-widget-share-1" %}
diff --git a/_includes/components/widgets/toc.njk b/_includes/components/widgets/toc.njk index 9470e02..fa835b0 100644 --- a/_includes/components/widgets/toc.njk +++ b/_includes/components/widgets/toc.njk @@ -1,9 +1,9 @@ {# Table of Contents Widget (for articles with headings) #} -{% if toc and toc.length %}

Contents

-{% endif %} diff --git a/theme/_includes/components/blog-sidebar.njk b/theme/_includes/components/blog-sidebar.njk index 54bde2e..fc73460 100644 --- a/theme/_includes/components/blog-sidebar.njk +++ b/theme/_includes/components/blog-sidebar.njk @@ -3,8 +3,12 @@ {# Each widget is wrapped in a collapsible container with localStorage persistence #} {% from "components/icon.njk" import icon %} +{% set isArticlePost = (postType == "article") or (page.url and page.url.startsWith('/articles/') and page.url != '/articles/') %} +{% set showArticleToc = isArticlePost %} + {% if homepageConfig and homepageConfig.blogPostSidebar and homepageConfig.blogPostSidebar.length %} {# === Data-driven mode: render configured widgets === #} + {% set hasConfiguredToc = '"toc"' in (homepageConfig.blogPostSidebar | dump) %} {% for widget in homepageConfig.blogPostSidebar %} {# Resolve widget title #} @@ -160,6 +164,21 @@
+ {% if showArticleToc and not hasConfiguredToc and (widget.type == "author-card" or widget.type == "author-card-compact") %} + {% set widgetKey = "post-widget-toc-article" %} +
+
+ +
+ {% include "components/widgets/toc.njk" %} +
+
+
+ {% endif %} + {% endfor %} {% else %} {# === Fallback: aligned with rmendes.net article sidebar === #} @@ -178,6 +197,22 @@ + {% if showArticleToc %} + {# Table of Contents (articles only) #} + {% set widgetKey = "post-widget-toc-article" %} +
+
+ +
+ {% include "components/widgets/toc.njk" %} +
+
+
+ {% endif %} + {# Share #} {% set widgetKey = "post-widget-share-1" %}
diff --git a/theme/_includes/components/widgets/toc.njk b/theme/_includes/components/widgets/toc.njk index 19a86d3..aaffdc3 100644 --- a/theme/_includes/components/widgets/toc.njk +++ b/theme/_includes/components/widgets/toc.njk @@ -1,9 +1,9 @@ {# Table of Contents Widget (for articles with headings) #} -{% if toc and toc.length %}

Contents

-
-{% endif %}