From de28c7fdeba86b711b791a19be27f95bf03795a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Fern=C3=A1ndez?= Date: Fri, 27 Oct 2023 02:03:59 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(comments):=20allow=20page=20ov?= =?UTF-8?q?erride=20of=20global=20system=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blog/mastering-tabi-settings/index.ca.md | 4 +- .../blog/mastering-tabi-settings/index.es.md | 4 +- content/blog/mastering-tabi-settings/index.md | 4 +- templates/page.html | 39 +++++++------------ 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/content/blog/mastering-tabi-settings/index.ca.md b/content/blog/mastering-tabi-settings/index.ca.md index 1d47f7b..875d81a 100644 --- a/content/blog/mastering-tabi-settings/index.ca.md +++ b/content/blog/mastering-tabi-settings/index.ca.md @@ -1,7 +1,7 @@ +++ title = "Domina la configuració de tabi: guia completa" date = 2023-09-18 -updated = 2023-10-05 +updated = 2023-10-27 description = "Descobreix les múltiples maneres en què pots personalitzar tabi." [taxonomies] @@ -454,6 +454,8 @@ Per activar els comentaris en una pàgina, establert el nom del sistema com a `t Si vols activar els comentaris de forma global, pots fer-ho establint `enabled_for_all_posts = true` a la secció apropiada del teu `config.toml` (per exemple, a `[extra.giscus]`). +Si has activat un sistema de forma global i vols desactivar-lo per a una pàgina específica, pots fer-ho establint el nom del sistema com a `false` al front matter. Per exemple, `utterances = false`. + Llegeix la [documentació](/ca/blog/comments/) per a més informació sobre els sistemes disponibles i la seva configuració. ### Anàlisi web diff --git a/content/blog/mastering-tabi-settings/index.es.md b/content/blog/mastering-tabi-settings/index.es.md index 71a039e..be00260 100644 --- a/content/blog/mastering-tabi-settings/index.es.md +++ b/content/blog/mastering-tabi-settings/index.es.md @@ -1,7 +1,7 @@ +++ title = "Domina la configuración de tabi: guía completa" date = 2023-09-18 -updated = 2023-10-05 +updated = 2023-10-27 description = "Descubre las múltiples maneras en que puedes personalizar tabi." [taxonomies] @@ -452,6 +452,8 @@ Para activar los comentarios en una página, establece el nombre del sistema com Si quieres activar los comentarios de forma global, puedes hacerlo estableciendo `enabled_for_all_posts = true` en la sección apropiada de tu `config.toml` (por ejemplo, en `[extra.giscus]`). +Si has activado un sistema globalmente, pero quieres desactivarlo en una página específica, puedes hacerlo estableciendo el nombre del sistema como `false` en el front matter. Por ejemplo, `utterances = false`. + Lee la [documentación](/es/blog/comments/) para obtener más información sobre los sistemas disponibles y su configuración. ### Análisis web diff --git a/content/blog/mastering-tabi-settings/index.md b/content/blog/mastering-tabi-settings/index.md index e9bd2c8..efa0619 100644 --- a/content/blog/mastering-tabi-settings/index.md +++ b/content/blog/mastering-tabi-settings/index.md @@ -1,7 +1,7 @@ +++ title = "Mastering tabi Settings: A Comprehensive Guide" date = 2023-09-18 -updated = 2023-10-05 +updated = 2023-10-27 description = "Discover the many ways you can customise your tabi site." [taxonomies] @@ -456,6 +456,8 @@ To enable comments on an individual page, set the name of the system you want to To enable a system globally (on all pages), set `enabled_for_all_posts = true` in the correct section of your `config.toml` (e.g. inside `[extra.giscus]`). +If you have enabled a system globally, but want to disable it on a specific page, set the name of the system to `false` in the front matter of that page. For example, `utterances = false`. + Read [the docs](/blog/comments/) for more information on the available systems and their setup. ### Analytics diff --git a/templates/page.html b/templates/page.html index a12b2e4..a204596 100644 --- a/templates/page.html +++ b/templates/page.html @@ -46,6 +46,7 @@ {% endfor %} #} +{# {{ __tera_context }} #} {# End debugging #}
@@ -107,33 +108,21 @@ {{ 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 %}