[IMP] documentation: make the multiversion, multilang work
Keep the language in multilang versions of pages. The canonical should look like: /documentation/user/12.0/sale.html -> /documentation/user/13.0/sale.html /documentation/user/11.0/fr/website.html -> /documentation/user/13.0/fr/website.html Needs the changes at odoo/saas-automation#40 that will change the canonical_root - from https://www.odoo.com/documentation/user/ - to https://www.odoo.com/documentation/user/12.0/ This way, the language switcher will keep the current version, changing from English to French will make /documentation/user/12.0/website.html -> /documentation/user/12.0/fr/website.html (and not -> /documentation/user/13.0/website.html as before)
This commit is contained in:
parent
299d2f544d
commit
f5833b7f1d
19
conf.py
19
conf.py
@ -361,8 +361,11 @@ def versionize(app, pagename, templatename, context, doctree):
|
||||
if not (app.config.canonical_root and app.config.versions):
|
||||
return
|
||||
|
||||
# remove last fragment containing the version
|
||||
root = '/'.join(app.config.canonical_root.rstrip('/').split('/')[:-1])
|
||||
|
||||
context['versions'] = [
|
||||
(vs, _build_url(app.config.canonical_root, vs, pagename))
|
||||
(vs, _build_url(root, vs, pagename))
|
||||
for vs in app.config.versions.split(',')
|
||||
if vs != app.config.version
|
||||
]
|
||||
@ -415,16 +418,24 @@ def canonicalize(app, pagename, templatename, context, doctree):
|
||||
""" Adds a 'canonical' URL for the current document in the rendering
|
||||
context. Requires the ``canonical_root`` setting being set. The canonical
|
||||
branch is ``master`` but can be overridden using ``canonical_branch``.
|
||||
/documentation/user/12.0/sale.html -> /documentation/user/13.0/sale.html
|
||||
/documentation/user/11.0/fr/website.html -> /documentation/user/13.0/fr/website.html
|
||||
"""
|
||||
if not app.config.canonical_root:
|
||||
return
|
||||
|
||||
# remove last fragment containing the version
|
||||
root = '/'.join(app.config.canonical_root.rstrip('/').split('/')[:-1])
|
||||
root += '/' + app.config.canonical_branch
|
||||
current_lang = app.config.language or 'en'
|
||||
|
||||
context['canonical'] = _build_url(
|
||||
app.config.canonical_root, app.config.canonical_branch, pagename)
|
||||
root, (current_lang != 'en' and current_lang or ''), pagename)
|
||||
|
||||
def _build_url(root, branch, pagename):
|
||||
if not branch:
|
||||
root = root.rstrip('/')
|
||||
root = root.rstrip('/')
|
||||
if branch:
|
||||
root += '/'
|
||||
return "{canonical_url}{canonical_branch}/{canonical_page}".format(
|
||||
canonical_url=root,
|
||||
canonical_branch=branch,
|
||||
|
Loading…
Reference in New Issue
Block a user