improved open graph for articles
This commit is contained in:
parent
d1926cfc17
commit
abee64a0de
1 changed files with 55 additions and 1 deletions
|
@ -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"""
|
||||
<meta property="og:site_name" content="Servala">
|
||||
<meta property="og:title" content="{title}">
|
||||
<meta property="og:description" content="{description}">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:type" content="{og_type}">
|
||||
<meta property="og:url" content="{request.build_absolute_uri()}">
|
||||
<meta property="og:image" content="{image_url}">
|
||||
"""
|
||||
|
||||
# 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"""
|
||||
<meta property="article:published_time" content="{article.created_at.isoformat()}">
|
||||
<meta property="article:modified_time" content="{article.updated_at.isoformat()}">
|
||||
<meta property="article:author" content="{article.author.get_full_name() or article.author.username}">
|
||||
"""
|
||||
|
||||
# Add article section if related to service, partner, or provider
|
||||
if article.related_service:
|
||||
article_tags += (
|
||||
f'\n <meta property="article:section" content="Services">'
|
||||
)
|
||||
elif article.related_consulting_partner:
|
||||
article_tags += (
|
||||
f'\n <meta property="article:section" content="Consulting Partners">'
|
||||
)
|
||||
elif article.related_cloud_provider:
|
||||
article_tags += (
|
||||
f'\n <meta property="article:section" content="Cloud Providers">'
|
||||
)
|
||||
else:
|
||||
article_tags += f'\n <meta property="article:section" content="General">'
|
||||
|
||||
# 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 <meta property="article:tag" content="{keyword}">'
|
||||
)
|
||||
|
||||
tags += article_tags
|
||||
|
||||
return mark_safe(tags)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue