Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/js/cards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$(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);
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);
}
});
});
8 changes: 2 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ 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("//([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/", 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):
Expand All @@ -73,8 +72,6 @@ def cards(pages, columns=1, style="cards", force_version=False):
cards.append(
CARDS_TEMPLATE % (
'/'.join((
'',
site,
project,
edition,
language,
Expand All @@ -83,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
)
)

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,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:
Expand Down