Skip to content

Commit

Permalink
✨ feat(comments): allow page override of global system
Browse files Browse the repository at this point in the history
Also refactors the logic to check if the systems are enabled
to be more maintainble.
  • Loading branch information
welpo committed Oct 27, 2023
1 parent 05ab241 commit d00a7aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
4 changes: 3 additions & 1 deletion content/blog/mastering-tabi-settings/index.ca.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion content/blog/mastering-tabi-settings/index.es.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion content/blog/mastering-tabi-settings/index.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
Expand Down
39 changes: 14 additions & 25 deletions templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
{% endfor %}
</tbody>
</table> #}
{# {{ __tera_context }} #}
{# End debugging #}

<main>
Expand Down Expand Up @@ -107,33 +108,21 @@ <h3>TL;DR:</h3>
{{ page.content | replace(from="<!-- toc -->", to=macros_toc::toc(page=page, header=false, language_strings=language_strings)) | safe }}
</section>

{# 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 %}
Expand Down

0 comments on commit d00a7aa

Please sign in to comment.