11

Improve your Pelican based website SEO by adding canonical url

 3 years ago
source link: https://www.andreagrandi.it/2020/10/14/improve-pelican-based-website-seo-adding-canonical-url/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Improve your Pelican based website SEO by adding canonical url

Posted on Wed 14 October 2020 in Development

You may have notice that a few days ago this website changed its template. I'm still using Pelican static generator, but I switched to a template named Flex.

The template is really nice and it's also optimised for mobile clients, but it's not very optimised for SEO.

I'm in no way an expert, so I tried to research for ways to optimise Pelican based websites and I discovered something I didn't know.

Content Duplication

If you are, like me, hosting your website on GitHub static pages, you should know that your published content is also duplicated on GitHub. For example: the pages you see on https://www.andreagrandi.it are all available here https://github.com/andreagrandi/andreagrandi.github.io

This is a problem for search engines, because the content is the same, but they don't know which one is the website you would like to be found in the search results.

Canonical URL

To solve this problem, pages needs to include a section like this:

<head>
    ...
    <link rel="canonical" href="https://www.andreagrandi.it/2020/10/11/python39-introduces-removeprefix-removesuffix/" />
</head>

So even if that page is found on GitHub Google will know that the "official" page is located at the canonical url and will use that url in the search results.

How to fix your Pelican template

Adding the canonical url in Pelican based websites is quite simple. You need to add a section like this to your base.html template file:

    ...
    {% if article %}
        <link rel="canonical" href="{{ SITEURL }}/{{ article.url }}" />
    {% endif%}
</head>

At this point, just rebuild and publish your pages and you are done!

References


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK