From b05c07d21c23a6ff7bbf1b6973c0ba8bd6944ade Mon Sep 17 00:00:00 2001
From: Philipp Oppermann
Date: Tue, 7 Jun 2022 10:06:09 +0200
Subject: [PATCH] Move comment threads for translated posts to separate
category
Avoids that a search for the post title returns a thread for a translated post.
---
blog/templates/edition-2/extra.html | 2 +-
blog/templates/edition-2/page.html | 7 ++++++-
blog/templates/news-page.html | 2 +-
blog/templates/snippets.html | 14 +++++++++++---
blog/templates/status-update-page.html | 2 +-
5 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/blog/templates/edition-2/extra.html b/blog/templates/edition-2/extra.html
index e6bb8d86..f4be5d5a 100644
--- a/blog/templates/edition-2/extra.html
+++ b/blog/templates/edition-2/extra.html
@@ -17,6 +17,6 @@
- {{ snippets::giscus(search_term=page.title ~ " (Extra Post)") }}
+ {{ snippets::giscus(search_term=page.title ~ " (Extra Post)", translated=false) }}
{% endblock after_main %}
diff --git a/blog/templates/edition-2/page.html b/blog/templates/edition-2/page.html
index f4b1aadf..5364bd82 100644
--- a/blog/templates/edition-2/page.html
+++ b/blog/templates/edition-2/page.html
@@ -118,7 +118,12 @@
{% else %}
{% set search_term=page.title %}
{% endif %}
- {{ snippets::giscus(search_term=search_term) }}
+ {% if page.lang != "en" %}
+ {% set translated = true %}
+ {% else %}
+ {% set translated = false %}
+ {% endif %}
+ {{ snippets::giscus(search_term=search_term, translated=translated) }}
{%- if page.lang != "en" %}
- {{ snippets::giscus(search_term=page.title ~ " (News Post)") }}
+ {{ snippets::giscus(search_term=page.title ~ " (News Post)", translated=false) }}
{% endblock after_main %}
diff --git a/blog/templates/snippets.html b/blog/templates/snippets.html
index 9065977e..1e1498c2 100644
--- a/blog/templates/snippets.html
+++ b/blog/templates/snippets.html
@@ -10,12 +10,20 @@
{% endmacro support %}
-{% macro giscus(search_term) %}
+{% macro giscus(search_term, translated) %}
+ {% if translated %}
+ {% set category = "Post Comments" %}
+ {% set category_path = "post-comments" %}
+ {% else %}
+ {% set category = "Post Comments (translated)" %}
+ {% set category_path = "post-comments-translated" %}
+ {% endif %}
+
{% if search_term is number %}
{% set discussion_url = "https://github.com/phil-opp/blog_os/discussions/" ~ search_term %}
{% else %}
{% set search_term_encoded = `"` ~ search_term ~ `"` | urlencode %}
- {% set discussion_url = `https://github.com/phil-opp/blog_os/discussions/categories/post-comments?discussions_q=` ~ search_term_encoded %}
+ {% set discussion_url = `https://github.com/phil-opp/blog_os/discussions/categories/` ~ category_path ~ `?discussions_q=` ~ search_term_encoded %}
{% endif %}