Skip to content

Commit

Permalink
Merge pull request #783 from maykinmedia/feature/1750-sharing-meta-tags
Browse files Browse the repository at this point in the history
✨ [#1750] Add meta tags for social media sharing
  • Loading branch information
alextreme authored Oct 4, 2023
2 parents 29bb3f8 + c901ddb commit 084b643
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/open_inwoner/pdc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def get_context_data(self, **kwargs):
config = SiteConfiguration.get_solo()
product = self.get_object()
context = super().get_context_data(**kwargs)
request = context["view"].request

subheadings = extract_subheadings(product.content, tag="h2")

Expand All @@ -221,6 +222,10 @@ def get_context_data(self, **kwargs):
if product.contacts.exists():
anchors.append(("#contact", _("Contact")))

context["meta_description"] = product.summary
if product.icon:
context["meta_image_url"] = request.build_absolute_uri(product.icon.url)
context["meta_page_url"] = request.build_absolute_uri(request.path)
context["anchors"] = anchors
context["related_products_start"] = 6 if product.links.exists() else 1
context["product_links"] = product.links.order_by("pk")
Expand Down
18 changes: 18 additions & 0 deletions src/open_inwoner/templates/master.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
<meta charset="utf-8">
<title>{% block title %}{% if page_title %}{{ page_title }} - {% endif %}{{ site_name }}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta property="og:title" content="{% if page_title %}{{ page_title }} - {% endif %}{{ site_name }}">
<meta name="twitter:title" content="{% if page_title %}{{ page_title }} - {% endif %}{{ site_name }}">
{% if meta_description %}
<meta property="og:description" content="{{ meta_description }}">
<meta name="twitter:description" content="{{ meta_description }}">
<meta name="description" content="{{ meta_description }}"/>
{% endif %}
{% if meta_image_url %}
<meta property="og:image" content="{{ meta_image_url }}">
<meta name="twitter:image" content="{{ meta_image_url }}">
{% endif %}
{% if meta_page_url %}
<meta property="og:url" content="{{ meta_page_url }}">
{% endif %}
<meta property="og:type" content="article">


{% if favicon %}<link rel="icon" href="{{ favicon }}" />
<link rel="apple-touch-icon" href="{{ favicon }}">{% endif %}

Expand Down

0 comments on commit 084b643

Please sign in to comment.