diff --git a/src/_includes/simple_page.njk b/src/_includes/simple_page.njk index 44f3000..b95306e 100644 --- a/src/_includes/simple_page.njk +++ b/src/_includes/simple_page.njk @@ -9,8 +9,9 @@ + {% if load_comments_script %} - + {% endif %}
diff --git a/static/assets/scripts/detectlang.js b/static/assets/scripts/detectlang.js new file mode 100644 index 0000000..46bc48c --- /dev/null +++ b/static/assets/scripts/detectlang.js @@ -0,0 +1,42 @@ +const SPANISH_MESSAGE = "Versión en español" +const SPANISH_BUTTON = "No mostrar esto de nuevo" +const ENGLISH_MESSAGE = "English page" +const ENGLISH_BUTTON = "Do not show me this again" + +if (redirect_notice_enabled()) { + let language = (navigator.language || navigator.userLanguage).split("-")[0] + if (location.pathname.startsWith("/en")) { + if (language === "es") { + add_redirect_notice(location.pathname.replace("/en", ""), SPANISH_MESSAGE, SPANISH_BUTTON) + } + } else if (!["weblog", "recommendations", "projects", "links"].includes(location.pathname.split("/")[1])) { + if (language !== "es") { + add_redirect_notice("/en" + location.pathname, ENGLISH_MESSAGE, ENGLISH_BUTTON) + } + } +} + +function add_redirect_notice(redirect, message, btn_message) { + let main = document.getElementsByTagName("main").item(0) + let div = document.createElement("div") + div.classList.add("redirect-notice") + div.innerHTML = `