From abee64a0de046beec7bec92c8bf70a5967307b40 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 6 Jun 2025 14:59:23 +0200 Subject: [PATCH] improved open graph for articles --- hub/services/templatetags/social_meta_tags.py | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/hub/services/templatetags/social_meta_tags.py b/hub/services/templatetags/social_meta_tags.py index cc2591d..03fe0cb 100644 --- a/hub/services/templatetags/social_meta_tags.py +++ b/hub/services/templatetags/social_meta_tags.py @@ -59,14 +59,68 @@ def social_meta_tags(context): else description ) + elif view_name == "services:article_detail" and "article" in context: + article = context["article"] + title = f"Servala - {article.title}" + description = article.excerpt + # Use article image if available, otherwise default + if article.image: + image_url = request.build_absolute_uri(article.image.url) + + # Determine og:type based on view + og_type = "website" # default + if view_name == "services:article_detail" and "article" in context: + og_type = "article" + # Generate the HTML for meta tags tags = f""" - + """ + # Add article-specific meta tags if this is an article detail page + if view_name == "services:article_detail" and "article" in context: + article = context["article"] + + # Add article-specific Open Graph tags + article_tags = f""" + + + + """ + + # Add article section if related to service, partner, or provider + if article.related_service: + article_tags += ( + f'\n ' + ) + elif article.related_consulting_partner: + article_tags += ( + f'\n ' + ) + elif article.related_cloud_provider: + article_tags += ( + f'\n ' + ) + else: + article_tags += f'\n ' + + # Add meta keywords as article tags if available + if article.meta_keywords: + keywords = [ + keyword.strip() + for keyword in article.meta_keywords.split(",") + if keyword.strip() + ] + for keyword in keywords: + article_tags += ( + f'\n ' + ) + + tags += article_tags + return mark_safe(tags)