From e24fd550e0a6e7e9c0cb513958696ff19d1183d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Wed, 15 Oct 2025 14:52:39 +0200 Subject: [PATCH] Make error page version aware --- docs/css/page-not-found.css | 35 +++++------------------------------ docs/js/error-page.js | 20 ++++++++++++++++++++ mkdocs.yml | 1 + theme/404.html | 4 ++-- 4 files changed, 28 insertions(+), 32 deletions(-) create mode 100644 docs/js/error-page.js diff --git a/docs/css/page-not-found.css b/docs/css/page-not-found.css index 0af53f3e7b..ea65ff0d2a 100644 --- a/docs/css/page-not-found.css +++ b/docs/css/page-not-found.css @@ -1,38 +1,13 @@ .page-not-found { - text-align: center; - margin: 50px; + display:flex; + flex-direction: column; + align-items: center; + margin: 50px; } .page-not-found h1 { font-weight: normal; + text-align: center; font-size: 37px; margin: 30px 0 10px; } - -.page-not-found h2 { - font-weight: normal; - font-size: 30px; - margin: 0 0 70px; -} - -.page-not-found h3 { - font-weight: normal; - font-size: 25px; - margin: 0 0 20px; - color: var(--dark-grey); -} - -.page-not-found ul { - display: inline-flex; - list-style-type: none; - margin: 0; -} - -.page-not-found ul li { - padding: 0 30px; - margin: 0; -} - -.page-not-found li + li { - border-left: 1px solid black; -} \ No newline at end of file diff --git a/docs/js/error-page.js b/docs/js/error-page.js new file mode 100644 index 0000000000..d0524a30a2 --- /dev/null +++ b/docs/js/error-page.js @@ -0,0 +1,20 @@ +(function (global, doc) { + const errorPageContainer = doc.querySelector('.page-not-found'); + + if (!errorPageContainer) { + return; + } + + // Replace all TOC links with the correct version + let currentVersion = '5.0'; + const branchNameRegexp = /\/en\/([a-z0-9-_.]*)\//g.exec(document.location.href); + + if (branchNameRegexp !== null && branchNameRegexp.hasOwnProperty(1) && branchNameRegexp[1].length) { + currentVersion = branchNameRegexp[1]; + } + + doc.querySelectorAll('.md-sidebar--primary .md-nav__item a, .page-not-found a').forEach(link => { + link.href = link.href.replace(/\/en\/([a-z0-9-_.]*)\//, `/en/${currentVersion}/`); + }); + +})(window, window.document); diff --git a/mkdocs.yml b/mkdocs.yml index 68158e1d8b..47d5f55373 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1001,6 +1001,7 @@ extra_javascript: - js/jquery.min.js - js/jquery-ui.min.js - js/custom.js + - js/error-page.js - js/release-notes.js - js/docs.switcher.js - '//cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js' diff --git a/theme/404.html b/theme/404.html index c227eecc96..e688b286bb 100644 --- a/theme/404.html +++ b/theme/404.html @@ -2,8 +2,8 @@ {% block content %}
- Not found

Page not found.

- Back to front page + Not found +

This link might be out-of-date. Go to the main documentation page or use the search to find what you are looking for.

{% endblock %}