From b75555cc87ca46e1135ce61a636ef04376fa72cf Mon Sep 17 00:00:00 2001 From: welpo Date: Fri, 27 Oct 2023 01:57:15 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(comments):=20allow=20page=20ov?= =?UTF-8?q?erride=20of=20global=20system?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also refactors the logic to check if the systems are enabled to be more maintainble. --- templates/page.html | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/templates/page.html b/templates/page.html index a12b2e4b1..a2045966c 100644 --- a/templates/page.html +++ b/templates/page.html @@ -46,6 +46,7 @@ {% endfor %} #} +{# {{ __tera_context }} #} {# End debugging #}
@@ -107,33 +108,21 @@

TL;DR:

{{ page.content | replace(from="", to=macros_toc::toc(page=page, header=false, language_strings=language_strings)) | safe }} - {# Check if comments are enabled #} - {% set giscus_enabled = config.extra.giscus.enabled_for_all_posts or page.extra.giscus %} - {% set utterances_enabled = config.extra.utterances.enabled_for_all_posts or page.extra.utterances %} - {% set hyvortalk_enabled = config.extra.hyvortalk.enabled_for_all_posts or page.extra.hyvortalk %} - {% set isso_enabled = config.extra.isso.enabled_for_all_posts or page.extra.isso %} - - {# Ensure only one comment system is enabled #} - {# Counter for enabled comment systems #} + {# Check if comments are enabled, checking that they are not disabled on the specific page #} + {% set systems = ["giscus", "utterances", "hyvortalk", "isso"] %} {% set enabled_systems = 0 %} + {% set comment_system = "" %} - {# Check and count the enabled comment systems #} - {% if giscus_enabled %} - {% set comment_system = "giscus" %} - {% set enabled_systems = enabled_systems + 1 %} - {% endif %} - {% if utterances_enabled %} - {% set comment_system = "utterances" %} - {% set enabled_systems = enabled_systems + 1 %} - {% endif %} - {% if hyvortalk_enabled %} - {% set comment_system = "hyvortalk" %} - {% set enabled_systems = enabled_systems + 1 %} - {% endif %} - {% if isso_enabled %} - {% set comment_system = "isso" %} - {% set enabled_systems = enabled_systems + 1 %} - {% endif %} + {% for system in systems %} + {% set global_enabled = config.extra[system].enabled_for_all_posts | default(value=false) %} + {% set page_enabled = page.extra[system] | default(value=global_enabled) %} + {% set is_enabled = global_enabled and page_enabled != false or page_enabled == true %} + + {% if is_enabled %} + {% set_global comment_system = system %} + {% set_global enabled_systems = enabled_systems + 1 %} + {% endif %} + {% endfor %} {# Ensure only one comment system is enabled #} {% if enabled_systems > 1 %}