From 85fe19df424f78ced450eb32915cda1712cae042 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. (cherry picked from commits: - fd5f6f49097ab916ff3f5daa433c6e57d0a59716, - e21df0671fe5a5aeb0e6253084dd842bad6114da, - 24781e377baad9375aaa7c7175e0bedb5c9c0414, - 66d185d5d2d51cfd8c28716930d1ca04ff51090b, - 3c79f3e3218bff53a6303e7b85ebe2089c09c4b6) Co-authored-by: Rémi Verschelde --- _templates/layout.html | 14 ++++++++++++++ conf.py | 35 ++++++++++++++++++++++++++++++++++- robots.txt | 4 ---- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 _templates/layout.html diff --git a/_templates/layout.html b/_templates/layout.html new file mode 100644 index 000000000..84503df34 --- /dev/null +++ b/_templates/layout.html @@ -0,0 +1,14 @@ +{% extends "!layout.html" -%} +{% block linktags -%} + {% if godot_inject_language_links -%} + {% for alternate_lang in godot_docs_supported_languages -%} + {# Convert to ISO 639-1 format, e.g. zh_CN -> zh-cn -#} + {% set alternate_lang_href = alternate_lang.lower().replace("_", "-") -%} + + {% endfor -%} + + + + {% endif -%} + {{ super() }} +{% endblock -%} diff --git a/conf.py b/conf.py index 8c1d1e2e7..06aca56ae 100644 --- a/conf.py +++ b/conf.py @@ -36,7 +36,32 @@ version = os.getenv("READTHEDOCS_VERSION", "2.1") # The full version, including alpha/beta/rc tags release = version -language = "en" +# Language / i18n + +supported_languages = { + "en": "Godot Engine (%s) documentation in English", + "de": "Godot Engine (%s) Dokumentation auf Deutsch", + "es": "Documentación de Godot Engine (%s) en español", + "fr": "Documentation de Godot Engine (%s) en français", + "fi": "Godot Engine (%s) dokumentaatio suomeksi", + "it": "Godot Engine (%s) documentazione in italiano", + "ja": "Godot Engine (%s)の日本語のドキュメント", + "ko": "Godot Engine (%s) 문서 (한국어)", + "pl": "Dokumentacja Godot Engine (%s) w języku polskim", + "pt_BR": "Documentação da Godot Engine (%s) em Português Brasileiro", + "ru": "Документация Godot Engine (%s) на русском языке", + "uk": "Документація до Godot Engine (%s) українською мовою", + "zh_CN": "Godot Engine (%s) 简体中文文档", +} + +language = os.getenv("READTHEDOCS_LANGUAGE", "en") +if not language in supported_languages.keys(): + print("Unknown language: " + language) + print("Supported languages: " + ", ".join(supported_languages.keys())) + print( + "The configured language is either wrong, or it should be added to supported_languages in conf.py. Falling back to 'en'." + ) + language = "en" exclude_patterns = ["_build"] @@ -76,6 +101,8 @@ html_theme_options = { # 'navigation_depth': 4, # Depth of the headers shown in the navigation bar } +html_title = supported_languages[language] % version + # VCS options: https://docs.readthedocs.io/en/latest/vcs.html#github html_context = { "display_github": True, # Integrate GitHub @@ -83,6 +110,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": list(supported_languages.keys()), + "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