forked from WdeNooy/Statistical-Inference
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path404.qmd
More file actions
91 lines (70 loc) · 2.48 KB
/
404.qmd
File metadata and controls
91 lines (70 loc) · 2.48 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
---
title: Page Not Found
---
Redirecting you to the correct page.
```{=html}
<script>
// Get the current URL
let currentUrl = window.location.href;
function updateURL(url) {
// Replace 'fig:' with 'fig-' if present
url = url.replace("fig:", "fig-");
const chapters = [
"01-samplingdistr.html",
"02-probability.html",
"03-estimation.html",
"04-hypothesis.html",
"07-anova.html",
"08-moderation-categorical.html",
"09-moderation-continuous.html",
"10-confounding.html",
"11-mediation.html",
"12-Appendix.html",
"13-colophon.html",
"14-references.html"
];
// Extract chapter number from URL
const chapterMatch = url.match(/(\d+)/);
const chapterNumber = chapterMatch ? parseInt(chapterMatch[0], 10) : null;
// Get anchor from URL
const anchorMatch = url.match(/(#.*$)/);
const anchor = anchorMatch ? anchorMatch[0] : "";
// Ensure chapter number is within valid range
if (chapterNumber !== null && chapterNumber >= 1 && chapterNumber <= chapters.length) {
return `https://shklinkenberg.github.io/Statistical-Inference/${chapters[chapterNumber - 1]}${anchor}`;
} else {
return url; // Return original URL if invalid chapter number
}
}
// Example usage test:
const url = "https://shklinkenberg.github.io/Statistical-Inference/11.2-discreterandomvariable.html#fig:random-variable";
let newUrl = updateURL(currentUrl)
// alert(newUrl);
// Redirect to the new URL
if (currentUrl !== newUrl) {
window.location.replace(newUrl);
}
</script>
```
```{r, eval=FALSE, echo=FALSE}
url = "https://shklinkenberg.github.io/Statistical-Inference/1.2-discreterandomvariable.html#fig:random-variable"
url = stringr::str_replace(url, "fig:", "fig-")
chapters = c("01-samplingdistr.html",
"02-probability.html",
"03-estimation.html",
"04-hypothesis.html",
"07-anova.html",
"08-moderation-categorical.html",
"09-moderation-continuous.html",
"10-confounding.html",
"11-mediation.html",
"12-Appendix.html",
"13-colophon.html",
"14-references.html")
# extract chapter number from url
chapter.number = stringr::str_extract(url, "[0-9]+")
# Get anchor from url
anchor = stringr::str_extract(url, "#.*$")
newURL = paste0("https://shklinkenberg.github.io/Statistical-Inference/", chapters[as.numeric(chapter.number)], anchor)
newURL
```