Skip to content

Commit

Permalink
Merge pull request #972 from okfn/901/open-graph-metadata
Browse files Browse the repository at this point in the history
Custom og:image for each page
  • Loading branch information
shashigharti authored Aug 29, 2023
2 parents e8c6d73 + 6a5089d commit 1055300
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
19 changes: 19 additions & 0 deletions foundation/organisation/migrations/0023_sidebarextension_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.3 on 2023-08-24 09:12

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("organisation", "0022_remove_networkgroup_working_groups_and_more"),
]

operations = [
migrations.AddField(
model_name="sidebarextension",
name="image",
field=models.ImageField(
blank=True, upload_to="organisation/sidebar/images"
),
),
]
1 change: 1 addition & 0 deletions foundation/organisation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,4 @@ class SignupForm(CMSPlugin):

class SideBarExtension(PageExtension):
enabled = models.BooleanField(default=True)
image = models.ImageField(upload_to="organisation/sidebar/images", blank=True)
10 changes: 6 additions & 4 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
<meta property="og:type" content="website"/>
<meta property="og:url"
content="{% if request.is_secure %}https://{% else %}http://{% endif %}{{ request.get_host }}{{ request.get_absolute_url }}"/>
<meta property="og:description"
content="{% page_attribute 'meta_description' %}"/>
<meta property="og:image"
content="{% static 'img/OKF-logo-white-background.png' %}"/>
<meta property="og:description" content="{% page_attribute 'meta_description' %}"/>
{% if request.current_page.sidebarextension.image.url != '' %}
<meta property="og:image" content="{{ request.current_page.sidebarextension.image.url }}"/>
{% else %}
<meta property="og:image" content="{% static 'img/OKF-logo-white-background.png' %}"/>
{% endif %}

{% block head-meta-fb-open-graph-extra %}{% endblock %}
{% endblock %}
Expand Down

0 comments on commit 1055300

Please sign in to comment.