When using AMP optimizer to process our Jekyll site built with Gulp, we encounter a number of warning messages like this: AMP Optimizer AddMandatoryTags WARNING No canonical param is given. Setting canonical href to .
We have traced the source of the issue to the jekyll-redirect-from plugin, which generates redirect pages with missing the HTML <head> and <body> tags. This is incompatible with the AMP optimizer and causing issues in the AMP pages.
Steps to reproduce
Install the jekyll-redirect-from plugin and enable it in the _config.yml file
Add some redirect_from entries to some pages or posts
Run gulp to build the site and run the AMP optimizer
Check the console output for the warning messages
Expected result
The redirect pages should have absolute URLs for their canonical links, and the AMP optimizer should not show any warning messages.
Actual result
The AMP optimizer cannot ampify the redirect pages appropriately and shows warning messages like this: AMP Optimizer AddMandatoryTags WARNING No canonical param is given. Setting canonical href to .
Proposed solution
One possible solution is to customize the redirect template for the jekyll-redirect-from plugin. We can copy the redirect.html file to the _layouts directory under the Jekyll project. In the custom redirect template, we then add back the HTML <head> and <body> tags.
Steps to implement the solution
[x] Update the jekyll-redirect-from plugin to the latest version
[x] Add the custom redirect template to the _layouts directory
[x] Test the site locally and verify the canonical links and the AMP validity
[x] Deploy the site to the hosting service and run the AMP optimizer again
[x] Check the console output for any remaining warning messages
[ ] Use the PageSpeed Insights tool to measure the site speed and performance
Description
When using AMP optimizer to process our Jekyll site built with Gulp, we encounter a number of warning messages like this:
AMP Optimizer AddMandatoryTags WARNING No canonical param is given. Setting canonical href to .
We have traced the source of the issue to the jekyll-redirect-from plugin, which generates redirect pages with missing the HTML
<head>
and<body>
tags. This is incompatible with the AMP optimizer and causing issues in the AMP pages.Steps to reproduce
_config.yml
fileredirect_from
entries to some pages or postsgulp
to build the site and run the AMP optimizerExpected result
The redirect pages should have absolute URLs for their canonical links, and the AMP optimizer should not show any warning messages.
Actual result
The AMP optimizer cannot ampify the redirect pages appropriately and shows warning messages like this:
AMP Optimizer AddMandatoryTags WARNING No canonical param is given. Setting canonical href to .
Proposed solution
One possible solution is to customize the redirect template for the jekyll-redirect-from plugin. We can copy the redirect.html file to the
_layouts
directory under the Jekyll project. In the custom redirect template, we then add back the HTML<head>
and<body>
tags.Steps to implement the solution
_layouts
directory