From 4158a4c3a14572d9ad94419f10a25bac050ac0c5 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Mon, 19 Feb 2024 08:21:07 +0100 Subject: [PATCH 1/6] main.py: cards: get right version from abs_url --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 790b5559..f6ebbb97 100644 --- a/main.py +++ b/main.py @@ -48,6 +48,8 @@ def cards(pages, columns=1, style="cards", force_version=False): canonical = current_page.canonical_url url_parts = re.search("//([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/", canonical) (site, project, edition, language, version) = url_parts.groups() + url_parts = re.search("^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/", absolute_url) + (project, edition, language, version) = url_parts.groups() version = force_version or version if isinstance(pages, str): @@ -87,4 +89,4 @@ def cards(pages, columns=1, style="cards", force_version=False): ) ) - return """
%s
""" % (style, columns, "\n".join(cards)) + return """
%s %s %s
""" % (style, columns, "\n".join(cards), current_page.abs_url, current_page.canonical_url) From 8187b0b369dbb6e718d99ef1192c7e0f2b89da7d Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 23 Feb 2024 11:03:27 +0100 Subject: [PATCH 2/6] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index f6ebbb97..29082d9d 100644 --- a/main.py +++ b/main.py @@ -89,4 +89,4 @@ def cards(pages, columns=1, style="cards", force_version=False): ) ) - return """
%s %s %s
""" % (style, columns, "\n".join(cards), current_page.abs_url, current_page.canonical_url) + return """
%s
""" % (style, columns, "\n".join(cards)) From d592f4b674c6963a5058f6673dc3045aa41cd34b Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 12 Apr 2024 09:57:44 +0200 Subject: [PATCH 3/6] main.py/cards: domain is not needed --- main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.py b/main.py index 29082d9d..72db6ab5 100644 --- a/main.py +++ b/main.py @@ -46,8 +46,6 @@ def cards(pages, columns=1, style="cards", force_version=False): current_page = env.variables.page absolute_url = current_page.abs_url canonical = current_page.canonical_url - url_parts = re.search("//([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/", canonical) - (site, project, edition, language, version) = url_parts.groups() url_parts = re.search("^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/", absolute_url) (project, edition, language, version) = url_parts.groups() version = force_version or version @@ -75,8 +73,6 @@ def cards(pages, columns=1, style="cards", force_version=False): cards.append( CARDS_TEMPLATE % ( '/'.join(( - '', - site, project, edition, language, From 10ba13db26465c22ceae0c305844b913cc70b183 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:50:50 +0200 Subject: [PATCH 4/6] main.py: clean-up --- main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.py b/main.py index 72db6ab5..b0ec0c4f 100644 --- a/main.py +++ b/main.py @@ -45,7 +45,6 @@ def include_file(filename, start_line=0, end_line=None, glue=''): def cards(pages, columns=1, style="cards", force_version=False): current_page = env.variables.page absolute_url = current_page.abs_url - canonical = current_page.canonical_url url_parts = re.search("^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/", absolute_url) (project, edition, language, version) = url_parts.groups() version = force_version or version @@ -81,7 +80,6 @@ def cards(pages, columns=1, style="cards", force_version=False): )), doc_meta['short'] or doc_meta['title'], doc_meta['description'] or " " - # site_url ) ) From 06aa957f02bfef5788bc94ebccc7db744e08d46e Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:40:07 +0200 Subject: [PATCH 5/6] cards.js to fix links --- docs/js/cards.js | 19 +++++++++++++++++++ mkdocs.yml | 1 + 2 files changed, 20 insertions(+) create mode 100644 docs/js/cards.js diff --git a/docs/js/cards.js b/docs/js/cards.js new file mode 100644 index 00000000..c814821a --- /dev/null +++ b/docs/js/cards.js @@ -0,0 +1,19 @@ +$(function() { + let version_path_index = 4; + $('.card-wrapper > div > a').each(function() { + let destUrl = $(this).attr('href'); + if ('//' === destUrl.substring(0, 2)) { + destUrl = document.location.protocol + destUrl; + } else if ('/' === destUrl.substring(0, 1)) { + destUrl = document.location.protocol + '//' + document.location.host + destUrl; + } + destUrl = new URL(destUrl); + let destPath = destUrl.pathname.split('/'), + srcPath = document.location.pathname.split('/'); + if (destPath[version_path_index] !== srcPath[version_path_index]) { + destPath[version_path_index] = srcPath[version_path_index]; + } + destUrl.pathname = destPath.join('/'); + $(this).attr('href', destUrl.href); + }); +}); diff --git a/mkdocs.yml b/mkdocs.yml index 533d5b68..20beda85 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -188,6 +188,7 @@ extra_javascript: - js/jquery-ui.min.js - js/custom.js - js/docs.switcher.js + - js/cards.js - '//cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js' markdown_extensions: From 40a2c14e1d133dc927f276f1d54fe2ba860e6892 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:28:56 +0200 Subject: [PATCH 6/6] cards.js: Now, hosts can be compared --- docs/js/cards.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/js/cards.js b/docs/js/cards.js index c814821a..f8b3d69b 100644 --- a/docs/js/cards.js +++ b/docs/js/cards.js @@ -8,12 +8,14 @@ $(function() { destUrl = document.location.protocol + '//' + document.location.host + destUrl; } destUrl = new URL(destUrl); - let destPath = destUrl.pathname.split('/'), - srcPath = document.location.pathname.split('/'); - if (destPath[version_path_index] !== srcPath[version_path_index]) { - destPath[version_path_index] = srcPath[version_path_index]; + if (destUrl.host === document.location.host) { + let destPath = destUrl.pathname.split('/'), + srcPath = document.location.pathname.split('/'); + if (destPath[version_path_index] !== srcPath[version_path_index]) { + destPath[version_path_index] = srcPath[version_path_index]; + } + destUrl.pathname = destPath.join('/'); + $(this).attr('href', destUrl.pathname); } - destUrl.pathname = destPath.join('/'); - $(this).attr('href', destUrl.href); }); });