From fd5f6f49097ab916ff3f5daa433c6e57d0a59716 Mon Sep 17 00:00:00 2001 From: Max Hilbrunner Date: Mon, 20 Apr 2020 22:18:48 +0200 Subject: [PATCH] Appease our great search engine overlords This hopefully fixes all translated pages showing up in search engine results, and makes the STABLE version of each page canonical. In turn, this allows us to re-enable indexing of the version-specific pages (see robots.txt changes), as search engines should prefer the canonical (stable) version, and only show the other versions if no canonical (stable) version exists (i.e. because that feature is only in latest, or was removed in stable). It adds proper canonical links for all generated pages, and fixes the existing links between the various translations of a page by both ensuring the pages links to itself with the proper language tag, and by properly linking to the full path of other translated versions. --- _templates/layout.html | 26 ++++++++++++-------------- conf.py | 12 ++++++++++++ robots.txt | 4 ---- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/_templates/layout.html b/_templates/layout.html index 63b560283..a10061e6d 100644 --- a/_templates/layout.html +++ b/_templates/layout.html @@ -1,14 +1,12 @@ -{% extends "!layout.html" %} -{% block linktags %} - - - - - - - - - - - {{ super() }} -{% endblock %} +{% extends "!layout.html" -%} +{% block linktags -%} + {% if godot_inject_language_links -%} + {% for alternate_lang in godot_docs_supported_languages -%} + + {% endfor -%} + + + + {% endif -%} + {{ super() }} +{% endblock -%} diff --git a/conf.py b/conf.py index 0598ee49e..c78504fbd 100644 --- a/conf.py +++ b/conf.py @@ -49,7 +49,13 @@ if env_tags is not None: tags.add(tag.strip()) # noqa: F821 # Language / i18n +supported_languages = ['en', 'de', 'es', 'fr', 'fi', 'it', 'ja', 'ko', 'pl', 'pt-br', 'ru', 'uk', 'zh-cn'] language = os.getenv("READTHEDOCS_LANGUAGE", "en") +if not language in supported_languages: + print("Unknown language: " + language) + print("Supported languages: " + ", ".join(supported_languages)) + print("This is an error or needs to be added to supported_languages in conf.py") + is_i18n = tags.has("i18n") # noqa: F821 exclude_patterns = ["_build"] @@ -94,6 +100,12 @@ html_context = { "github_repo": "godot-docs", # Repo name "github_version": "master", # Version "conf_py_path": "/", # Path in the checkout to the docs root + "godot_inject_language_links": True, + "godot_docs_supported_languages": supported_languages, + "godot_docs_basepath": "https://docs.godotengine.org/", + "godot_docs_suffix": ".html", + "godot_default_lang": "en", + "godot_canonical_version": "stable", } html_logo = "img/docs_logo.png" diff --git a/robots.txt b/robots.txt index 015c50aad..06d70556d 100644 --- a/robots.txt +++ b/robots.txt @@ -1,7 +1,3 @@ user-agent: * -disallow: /*/3.2 -disallow: /*/3.1 -disallow: /*/3.0 -disallow: /*/2.1 sitemap: https://docs.godotengine.org/sitemap.xml