Add option to output canonical URL

Canonical links are handy to tell search engines which page is
canonical amongst various permutations of URLs (e.g. https vs. http
and www subdomain or not).  Add an option to output one via the
following pelicanconf.py setting:

REL_CANONICAL = True
This commit is contained in:
saagit 2020-08-16 08:37:49 -07:00
parent 0f0ea7e824
commit 0e88f3ee9f

View file

@ -115,6 +115,19 @@
<meta name="msapplication-TileColor" content="{{ BROWSER_COLOR }}"> <meta name="msapplication-TileColor" content="{{ BROWSER_COLOR }}">
{% endif %} {% endif %}
{% if REL_CANONICAL %}
{% if page %}
<link rel="canonical" href="{{ SITEURL }}/{{ page.url }}">
{% elif article %}
<link rel="canonical" href="{{ SITEURL }}/{{ article.url }}">
{% elif page_name == 'index' and not articles_previous_page %}
<link rel="canonical" href="{{ SITEURL }}">
{% elif author or category or tag or page_name == 'index' %}
<link rel="canonical" href="{{ SITEURL }}/{{ articles_page.url }}">
{% else %}
<link rel="canonical" href="{{ SITEURL }}/{{ output_file }}">
{% endif %}
{% endif %}
{% block meta %} {% block meta %}
<meta name="author" content="{{ AUTHOR }}" /> <meta name="author" content="{{ AUTHOR }}" />
<meta name="description" content="{{ SITEDESCRIPTION }}" /> <meta name="description" content="{{ SITEDESCRIPTION }}" />