Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonical URL - is it injected correctly or should it? #120

Open
benjaoming opened this issue Feb 1, 2023 · 3 comments
Open

Canonical URL - is it injected correctly or should it? #120

benjaoming opened this issue Feb 1, 2023 · 3 comments
Assignees

Comments

@benjaoming
Copy link

A canonical URL such as <link rel="canonical" href="https://docs.readthedocs.io/en/stable/index.html" /> is already inserted in themes.

However, this extension proposes to add it again.

{%- if canonical_url %}
{%- if pagename == "index" %}
{%- set canonical_page = "" %}
{%- elif pagename.endswith("/index") %}
{%- set canonical_page = pagename[:-("/index"|length)] + "/" %}
{%- else %}
{%- set ending = "/" if 'dirhtml' in builder else ".html" %}
{%- set canonical_page = pagename + ending %}
{%- endif %}
<!--
Always link to the latest version, as canonical.
http://docs.readthedocs.org/en/latest/canonical.html
-->
<link rel="canonical" href="{{ canonical_url|e }}{{ canonical_page }}" />
{%- endif %}

Adding this issue to clarify what this approach is about and if it's a potential solution to upstream Sphinx issues.

CC: @ericholscher

@benjaoming benjaoming self-assigned this Feb 1, 2023
@ericholscher
Copy link
Member

That is where we can inject logic to fix the Sphinx bug, as needed, instead of in the theme. It will then apply to all RTD sphinx projects.

@benjaoming
Copy link
Author

Won't it be a problem to inject <link rel="canonical" href="{{ canonical_url|e }}{{ canonical_page }}" /> if it's already defined previously by the theme?

@ericholscher
Copy link
Member

Perhaps? Seems like something we should hopefully be able to check for, and be smart about, but it's definitely a hack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants