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 26, 2023
1 parent 05ab241 commit b75555c
Showing 1 changed file with 14 additions and 25 deletions.
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 b75555c

Please sign in to comment.