Skip to content

Commit 06aa957

Browse files
committed
cards.js to fix links
1 parent 9823e9e commit 06aa957

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

docs/js/cards.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
$(function() {
2+
let version_path_index = 4;
3+
$('.card-wrapper > div > a').each(function() {
4+
let destUrl = $(this).attr('href');
5+
if ('//' === destUrl.substring(0, 2)) {
6+
destUrl = document.location.protocol + destUrl;
7+
} else if ('/' === destUrl.substring(0, 1)) {
8+
destUrl = document.location.protocol + '//' + document.location.host + destUrl;
9+
}
10+
destUrl = new URL(destUrl);
11+
let destPath = destUrl.pathname.split('/'),
12+
srcPath = document.location.pathname.split('/');
13+
if (destPath[version_path_index] !== srcPath[version_path_index]) {
14+
destPath[version_path_index] = srcPath[version_path_index];
15+
}
16+
destUrl.pathname = destPath.join('/');
17+
$(this).attr('href', destUrl.href);
18+
});
19+
});

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ extra_javascript:
188188
- js/jquery-ui.min.js
189189
- js/custom.js
190190
- js/docs.switcher.js
191+
- js/cards.js
191192
- '//cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js'
192193

193194
markdown_extensions:

0 commit comments

Comments
 (0)