improve LD config

This commit is contained in:
Tobias Brunner 2025-06-23 13:23:28 +02:00
parent 18232ee276
commit 4aebccbc7b
No known key found for this signature in database
2 changed files with 76 additions and 13 deletions

View file

@ -1,12 +1,17 @@
{% extends 'base.html' %}
{% load static %}
{% load contact_tags %}
{% load json_ld_tags %}
{% block title %}Managed {{ offering.service.name }} on {{ offering.cloud_provider.name }}{% endblock %}
{% block extra_js %}
<script defer src="{% static "js/price-calculator.js" %}"></script>
<link rel="stylesheet" type="text/css" href='{% static "css/price-calculator.css" %}'>
<!-- JSON-LD Structured Data -->
{% json_ld_structured_data %}
<style>
/* Subtle styling for the best plan */
.card.border-success.border-2 {

View file

@ -209,7 +209,7 @@ def json_ld_structured_data(context):
data = {
"@context": "https://schema.org",
"@type": "Product",
"name": f"{offering.service.name} on {offering.cloud_provider.name}",
"name": f"Managed {offering.service.name} on {offering.cloud_provider.name}",
"description": offering.description or offering.service.description,
"url": offering_url,
"category": "Cloud Service",
@ -224,18 +224,76 @@ def json_ld_structured_data(context):
# Add offers if available
if hasattr(offering, "plans") and offering.plans.exists():
data["offers"] = {
"@type": "AggregateOffer",
"availability": "https://schema.org/InStock",
"offerCount": offering.plans.count(),
"seller": {
"@type": "Organization",
"name": offering.cloud_provider.name,
"url": request.build_absolute_uri(
offering.cloud_provider.get_absolute_url()
),
},
}
# Get all plans with pricing
plans_with_prices = offering.plans.filter(plan_prices__isnull=False).distinct()
if plans_with_prices.exists():
# Create individual offers for each plan
offers = []
all_prices = []
for plan in plans_with_prices:
plan_prices = plan.plan_prices.all()
if plan_prices.exists():
first_price = plan_prices.first()
all_prices.extend([p.amount for p in plan_prices])
offer = {
"@type": "Offer",
"name": plan.name,
"price": str(first_price.amount),
"priceCurrency": first_price.currency,
"availability": "https://schema.org/InStock",
"url": offering_url + "#plan-order-form",
"seller": {
"@type": "Organization",
"name": "VSHN"
}
}
offers.append(offer)
# Add aggregate offer with all individual offers
data["offers"] = {
"@type": "AggregateOffer",
"availability": "https://schema.org/InStock",
"offerCount": len(offers),
"offers": offers,
"seller": {
"@type": "Organization",
"name": "VSHN"
}
}
# Add lowPrice, highPrice and priceCurrency if we have prices
if all_prices:
data["offers"]["lowPrice"] = str(min(all_prices))
data["offers"]["highPrice"] = str(max(all_prices))
# Use the currency from the first plan's first price
first_plan_with_prices = plans_with_prices.first()
first_currency = first_plan_with_prices.plan_prices.first().currency
data["offers"]["priceCurrency"] = first_currency
# Note: aggregateRating and review fields are not included as this is a B2B
# service marketplace without a review system. These could be added in the future
# if customer reviews/ratings are implemented.
# Example structure for future implementation:
# if hasattr(offering, 'reviews') and offering.reviews.exists():
# data["aggregateRating"] = {
# "@type": "AggregateRating",
# "ratingValue": "4.5",
# "reviewCount": "10"
# }
else:
# No pricing available, just basic offer info
data["offers"] = {
"@type": "AggregateOffer",
"availability": "https://schema.org/InStock",
"offerCount": offering.plans.count(),
"seller": {
"@type": "Organization",
"name": "VSHN"
}
}
else:
# Default to organization data if no specific page type matches