back-to-landing.js 49 lignes · 1706 octets
// Injecte un lien "← gitrust.eu" dans la menu-bar mdBook quand la doc est
// servie sous un sous-chemin /<lang>/docs/ de la landing gitrust.eu.
//
// Détection :
//   - location.pathname commence par /<lang>/docs/
//   - location.hostname se termine par "gitrust.eu" (ou env staging.*gitrust.eu)
//
// En dev local (localhost, file://), ne fait rien.

(function () {
  "use strict";

  function init() {
    var path = window.location.pathname || "";
    var host = window.location.hostname || "";

    var m = path.match(/^\/([a-z]{2})\/docs\//);
    if (!m) return;
    if (!/gitrust\.(eu|nuage\.ebii)(:\d+)?$/.test(host)) return;

    var lang = m[1];
    var menuBar = document.querySelector("#menu-bar, .menu-bar");
    if (!menuBar) return;

    var a = document.createElement("a");
    a.href = "/" + lang + "/";
    a.className = "gitrust-back-to-landing icon-button";
    a.setAttribute("aria-label", "Retour au site principal gitrust.eu");
    a.innerHTML =
      '<span aria-hidden="true" style="font-size:1.1em;padding-right:.35em;">←</span>' +
      '<span>gitrust.eu</span>';

    // Style inline : simple et robuste, ne dépend pas du thème
    a.style.cssText =
      "display:inline-flex;align-items:center;gap:0;padding:0 .75em;" +
      "margin-left:.4em;height:2.1rem;font-weight:600;font-size:.95rem;" +
      "color:var(--fg);text-decoration:none;border-right:1px solid rgba(43,43,60,0.12);" +
      "white-space:nowrap;";

    // Insérer en premier (à gauche de l'icône sidebar-toggle)
    menuBar.insertBefore(a, menuBar.firstChild);
  }

  if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", init);
  } else {
    init();
  }
})();