Skip to content

Commit

Permalink
Merge pull request #127 from springload/chore/opengraph-setup
Browse files Browse the repository at this point in the history
Opengraph setup
  • Loading branch information
haydngreatnews authored Jul 14, 2024
2 parents 2f4b6c2 + 959d1c8 commit f565268
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
8 changes: 5 additions & 3 deletions cdhweb/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings
from django.templatetags.static import static
from wagtail.models import Site

from cdhweb.pages.utils import absolutize_url
Expand All @@ -14,14 +15,15 @@ def template_settings(request):
if "purple-mode" in feature_flags:
default_preview_img = "img/alt-modes/purple/cdhlogo_square.png"
else:
default_preview_img = "img/cdhlogo_square.jpg"
default_preview_img = "images/cdhlogo_square.jpg"

context_extras = {
"SHOW_TEST_WARNING": getattr(settings, "SHOW_TEST_WARNING", False),
"site": Site.find_for_request(request),
"default_preview_image": absolutize_url(
"".join([settings.STATIC_URL, default_preview_img])
"default_preview_image": request.build_absolute_uri(
static(default_preview_img)
),
# try using template tag import static tag and use here instead of join django utils static
# Include analytics based on settings.DEBUG or override in settings.py
# Defaults to opposite of settings.DEBUG
"INCLUDE_ANALYTICS": getattr(settings, "INCLUDE_ANALYTICS", not settings.DEBUG),
Expand Down
Binary file added static/images/alt-modes/purple/cdhlogo_square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/cdhlogo_square.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 7 additions & 14 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

<head>
<meta charset="utf-8">
<title>{% block title %}{% if self.seo_title %}{{ self.seo_title }}{% else %}{{ self.title }}{% endif %}{% endblock %}{% block title_suffix %}{% endblock %}</title>
<meta name="description" content="{% firstof self.search_description self.intro|default:''|striptags self.body_excerpt|default:''|striptags|truncatewords:40 self.title %}">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>{% block title %}{% if self.seo_title %}{{ self.seo_title }}{% else %}{{ self.title }}{% endif %}{% endblock %}{% block title_suffix %}{% endblock %}</title>

{% include "includes/favicons.html" %}
{% include "snippets/head_meta.html" %}

<script type="text/javascript"> window.staticRoot = "{% static 'dist/' %}"; </script>

Expand All @@ -16,22 +19,12 @@
document.documentElement.classList.add('js');
</script>

{% include "includes/favicons.html" %}

{% comment %}
{% include "core/includes/meta/twitter_card.html" %}
{% include "core/includes/meta/open_graph.html" %}

{% block og_images %}
{% include "core/includes/meta/open_graph_image.html" %}
{% endblock %}

{% endcomment %}
{% block extra_css %}
{# Needed for specific cases #}
{% endblock %}

<script defer src="{% static 'dist/main.js' %}"></script><link href="{% static 'dist/styles.css' %}" rel="stylesheet"></head>
<script defer src="{% static 'dist/main.js' %}"></script>
<link href="{% static 'dist/styles.css' %}" rel="stylesheet">

</head>
<body class="{% block body_class %}{% endblock %}">
Expand Down
2 changes: 1 addition & 1 deletion templates/snippets/head_meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% autoescape on %}
{# html metadata #}
{% if page.tags.exists %}<meta name="keywords" content="{{ page.tags.all|join:', ' }}"/>{% endif %}
{% if meta_description %}<meta name="description" content="{{ meta_description|striptags }}"/>{% endif %}
<meta name="description" content="{% firstof self.search_description self.intro|default:''|striptags self.body_excerpt|default:''|striptags|truncatewords:40 self.title %}">
{# determine preview image: specified by page, cdh icon based on url, or default image #}
{# open graph metadata #}
<meta property="og:title" content="{{ meta_title }}" />
Expand Down

0 comments on commit f565268

Please sign in to comment.