emencia / django-blog-lotus

A weblog application with Django.
https://django-blog-lotus.readthedocs.io/
MIT License
6 stars 1 forks source link

Canonical URL #67

Closed kase947 closed 10 months ago

kase947 commented 11 months ago

We need to add this block in Lotus base.html :

{% block header-resource-extra %}
    {{ block.super }}
    <link rel="canonical" href="{{ SITE.web_url }}{{ request.path }}">
{% endblock header-resource-extra %}
sveetch commented 10 months ago

Currently in v0.8.0 pre release 3 it has been implemented a little bit different:

{% block header-resource-extra %}
    {{ block.super }}
    <link rel="canonical" href="{{ request.scheme }}://{{ request.site.domain }}{{ request.path }}">
{% endblock header-resource-extra %}

This is because SITE variable is not available from common Django projects, it is something that comes from a custom template context processor from your project so we can not stand on it and so instead my template is using the Site object from django.contrib.sites.middleware.CurrentSiteMiddleware . Note that this middleware will have to be added to your project settings if you want to use the same template or you will have to stick with your custom one.

Note that in both case, if your site is available on both HTTP and HTTPS, the canonical url scheme will change, there is no way for Django to know about a unique scheme you would enforce on HTTP or HTTPS site.