-
Notifications
You must be signed in to change notification settings - Fork 310
Expand file tree
/
Copy pathextra.js
More file actions
111 lines (93 loc) · 3.6 KB
/
extra.js
File metadata and controls
111 lines (93 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// add classes for code-block-filename styling
$('.rst-content pre')
.prev('blockquote')
.addClass('code-block-filename');
var tabConversionIterations = 0
// convert tab admonition to tabs
while (true) {
const firstTab = $('.rst-content .admonition.tab').first()
if (firstTab.length == 0) break;
const otherTabs = firstTab.nextUntil(':not(.admonition.tab)');
const allTabs = $($.merge($.merge([], firstTab), otherTabs));
const tabContainer = $('<div>').addClass('tabs');
const headerContainer = $('<div>').addClass('tabs-header');
const contentContainer = $('<div>').addClass('tabs-content');
tabContainer.insertBefore(firstTab);
tabContainer.append(headerContainer, contentContainer)
// add extra classes from the first tab to the container
const classes = Array.from(firstTab[0].classList)
for (let i = 0; i < classes.length; i++) {
const element = classes[i];
if (element == 'tab' || element == 'admonition') {
continue
}
tabContainer.addClass(element)
}
const selectTab = function (index) {
headerContainer.children().removeClass('active')
headerContainer.children().eq(index).addClass('active')
contentContainer.children().hide()
contentContainer.children().eq(index).show()
}
allTabs.each(function (tabI, el) {
const $el = $(el)
const titleElement = $el.children('.admonition-title')
const title = titleElement.text()
const button = $('<button>').text(title)
button.click(function () {
selectTab(tabI)
})
headerContainer.append(button)
titleElement.remove()
$el.removeClass('admonition')
contentContainer.append($el)
})
selectTab(0)
// this will catch infinite loops which can occur when editing the above
if (tabConversionIterations++ > 1000) throw 'too many iterations'
}
/**
* Redirects the current page based on the path and fragment identifier (hash) in the URL.
*
* Example usage:
* fragmentRedirect([
* { source: 'setup/#github-actions', destination: 'ci-services' }
* { source: 'faq/#macosx', destination: 'platforms#apple' }
* ])
*/
function fragmentRedirect(redirects) {
const href = window.location.href;
const hash = window.location.hash;
for (const redirect of redirects) {
const source = redirect.source;
const destination = redirect.destination;
if (endswith(href, source)) {
// Redirect to the destination path, with the same fragment identifier
// specified in the destination path, otherwise, keep the same hash
// from the current URL.
const destinationIncludesHash = destination.includes('#');
let newUrl = href.replace(source, destination);
if (!destinationIncludesHash) {
newUrl += hash;
}
console.log('Redirecting to:', newUrl);
window.location.replace(newUrl);
return
}
}
}
function endswith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
fragmentRedirect([
{ source: 'setup/#github-actions', destination: 'ci-services/' },
{ source: 'setup/#azure-pipelines', destination: 'ci-services/' },
{ source: 'setup/#travis-ci', destination: 'ci-services/' },
{ source: 'setup/#appveyor', destination: 'ci-services/' },
{ source: 'setup/#circleci', destination: 'ci-services/' },
{ source: 'setup/#gitlab-ci', destination: 'ci-services/' },
{ source: 'setup/#cirrus-ci', destination: 'ci-services/' },
{ source: 'faq/#linux-builds-in-containers', destination: 'platforms/#linux-containers' },
{ source: 'faq/#apple-silicon', destination: 'platforms/#macos-architectures' },
{ source: 'faq/#windows-arm64', destination: 'platforms/#windows-arm64' },
]);