datamade / how-to

📚 Doing all sorts of things, the DataMade way
MIT License
81 stars 12 forks source link

Pre-bake a few more things into our new Django app template #227

Closed hancush closed 2 years ago

hancush commented 2 years ago

Documentation request

settings.py

if os.getenv('DJANGO_ALLOW_SEARCH_INDEXING', False) == 'True':
    ALLOW_SEARCH_INDEXING = True
else:
    ALLOW_SEARCH_INDEXING = False

context_processors.py

from django.conf import settings

def base_context(request):
    return {
        'allow_index': settings.ALLOW_SEARCH_INDEXING
    }

base.html

<meta name="robots" content="{% if allow_index %}all{% else %}noindex{% endif %}">
{% if allow_index %}
<link rel="canonical" href="${FILL IN PRODUCTION DOMAIN WITH NO TRAILING SLASH HERE}{{ request.path }}" />
{% endif %}

base.html

    <meta property="og:title" content="{{ page.title }}">
    <meta property="og:url" content="{{ request.build_absolute_uri }}">
    <meta property="og:image" content="{{ request.scheme }}://{{ request.get_host }}${ADD THE STATIC TAG WITH THE PATH TO YOUR SHARE CARD HERE}">

    <!-- Twitter metadata -->
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="{{ page.title }}">
    <meta name="twitter:url" content="{{ request.build_absolute_uri }}">
    <meta name="twitter:image" content="{{ request.scheme }}://{{ request.get_host }}${ADD THE STATIC TAG WITH THE PATH TO YOUR SHARE CARD HERE}">