[IMP] _extension: add languages link

To refer the pages in different languages for better indexing
This commit is contained in:
Martin Trigaux 2019-12-10 14:44:57 +01:00
parent 2e3f82e0b8
commit 538eecd2db
2 changed files with 11 additions and 0 deletions

View File

@ -25,6 +25,13 @@
{{ super() }}
{%- endblock -%}
{%- block linktags -%}
{% for code, url in language_codes %}
<link rel="alternate" hreflang="{{ code }}" href="{{ url }}" />
{%- endfor %}
{{ super() }}
{%- endblock -%}
{%- block sidebar1 -%}{%- endblock -%}
{%- block sidebar2 -%}{%- endblock -%}
{%- block relbar1 -%}{%- endblock -%}

View File

@ -404,6 +404,10 @@ def localize(app, pagename, templatename, context, doctree):
for la in app.config.languages.split(',')
if la != current_lang
]
context['language_codes'] = [
(la.split('_')[0] if la != 'en' else 'x-default', _build_url(app.config.canonical_root, (la != 'en' and la or ''), pagename))
for la in app.config.languages.split(',')
]
def _build_url(root, branch, pagename):