Add option to output canonical URL (#240)

* 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-12-01 10:39:12 -08:00 committed by GitHub
parent 7150568800
commit 17565a6365
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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 }}" />