Skip to content

Commit a79fb2e

Browse files
committed
feat: #304 add meta tags for organization public page
1 parent 726784f commit a79fb2e

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

django_email_learning/public/views.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@
1414
)
1515

1616

17+
def json_ld_from(
18+
courses: list[PublicCourseSerializer], organization: Organization
19+
) -> dict:
20+
course_list = []
21+
for course in courses:
22+
course_data = {
23+
"@type": "Course",
24+
"name": course.title,
25+
"description": course.description,
26+
"inLanguage": course.language,
27+
"provider": {
28+
"@type": "Organization",
29+
"name": organization.name,
30+
},
31+
}
32+
if course.image:
33+
course_data["image"] = course.image
34+
course_list.append(course_data)
35+
return {
36+
"@context": "https://schema.org",
37+
"@type": "ItemList",
38+
"itemListElement": course_list,
39+
}
40+
41+
1742
@method_decorator(ensure_csrf_cookie, name="dispatch")
1843
class OrganizationView(TemplateView):
1944
template_name = "public/organization.html"
@@ -82,6 +107,16 @@ def get_context_data(self, **kwargs) -> dict: # type: ignore[no-untyped-def]
82107
"course_language": _("Course language"),
83108
},
84109
}
110+
context["organization_name"] = organization.name
111+
context["organization_description"] = organization.description
112+
context["organization_logo_url"] = (
113+
self.request.build_absolute_uri(organization.logo.url)
114+
if organization.logo
115+
else None
116+
)
117+
118+
if len(courses) > 0:
119+
context["json_ld"] = json_ld_from(courses, organization)
85120
context["page_title"] = organization.name
86121
return context
87122

django_email_learning/templates/public/base.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
{{ appContext | json_script:"app-context" }}
1212
<meta charset="UTF-8" />
1313
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
14+
{% block meta_tags %}{% endblock %}
1415
<link rel="icon" type="image/png" href="{% static 'logo.png' %}" />
1516
<title>{% block title %}{{ page_title }}{% endblock %}</title>
1617
</head>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
{% extends "public/base.html" %}
2+
{% load i18n %}
23
{% load django_vite %}
34
{% block head_script %}
45
{% vite_asset 'public/organization/Organization.jsx' %}
6+
{% if json_ld %}
7+
<script type="application/ld+json">{{ json_ld|safe }}</script>
8+
{% endif %}
9+
{% endblock %}
10+
{% block meta_tags %}
11+
<meta name="description" content="{% blocktranslate %}Courses provided by {{ organization_name }}{% endblocktranslate %}, {{ organization_description }}">
12+
<meta property="og:type" content="website">
13+
<meta property="og:url" content="{{ request.build_absolute_uri }}">
14+
<meta property="og:title" content="{% blocktranslate %} Courses by {{ organization_name }} {% endblocktranslate %}">
15+
{% if organization_description %}<meta property="og:description" content="{{ organization_description }}">{% endif %}
16+
{% if organization_logo_url %}<meta property="og:image" content="{{ organization_logo_url }}">{% endif %}
17+
18+
<meta name="twitter:card" content="summary_large_image">
19+
<meta name="twitter:title" content="{% blocktranslate %} Courses by {{ organization_name }} {% endblocktranslate %}">
20+
{% if organization_description %}<meta name="twitter:description" content="{{ organization_description }}">{% endif %}
21+
{% if organization_logo_url %}<meta name="twitter:image" content="{{ organization_logo_url }}">{% endif %}
522
{% endblock %}

0 commit comments

Comments
 (0)