Navigation updates and fixes
[exim-website.git] / templates / static / doc / chapter.js
index add4bd3184415e1a0b2102a25889491050cd97b5..45bb4afc7f40680d47757413b7be90f5011cf342 100644 (file)
@@ -1,3 +1,19 @@
+// Rewrite chapter urls using the canonical name. e.g ch01.html becomes introduction.html
+(function ($) {
+    if (document.location.pathname.match(/\/ch\d+\.html$/)) {
+        var url = document.location.href;
+        var canonical = $('link[rel="canonical"]').attr('href');
+        if (canonical) {
+            canonical = canonical.replace(/^[^#]+(\/[^\/#]+).*/,'$1');
+            url = url.replace(/\/ch\d+\.html/, canonical);
+            if ("history" in window && "replaceState" in window.history)
+                window.history.replaceState("", document.title, url);
+            else
+                document.location.href = url;
+        }
+    }
+})(jQuery);
+
 // Warnings about reading old version of documentation
 (function ($) {
     if( $.grep( document.cookie.split(/\s*;\s*/), function(a){return a === 'old_version_warning_removed=true' ? true : false }).length === 0 ){