-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
112 lines (92 loc) · 2.89 KB
/
index.html
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
112
<!DOCTYPE html>
<html>
<head>
<title>Wiki:punkto</title>
<style>
@import url("https://geheimesite.nl/base.css");
section {
width: 500px;
margin: 15px;
padding: 45px 35px;
word-wrap: break-word;
box-shadow: 10px 10px 30px 10px rgba(0, 0, 0, 0.1);
position: absolute;
background: light-dark(white, #2b2b33);
}
[data-page="404"] {
color: gray;
font-style: italic;
padding: 20px 30px;
}
section :first-child {
margin-top: 0;
}
section :last-child {
margin-bottom: 0;
}
</style>
</head>
<body>
<main>
<noscript>
I'm afraid this monstrosity required JavaScript to function. Sorry!
</noscript>
</main>
<script type="module">
import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";
const container = document.querySelector("main");
// This tracks the mouse position. Needed because JavaScript sucks
// and doesn't allow me to read the mouse position at an arbitrary
// point in the code :(
let mouseX = 0;
let mouseY = 0;
document.addEventListener("mousemove", (event) => {
mouseX = event.clientX;
mouseY = event.clientY;
});
// The fun stuff is down here (as always ;)
function openPage(page, x, y) {
fetch(`/${page}.md`).then(async (response) => {
const section = document.createElement("section");
section.style.top = y + "px";
section.style.left = x + "px";
section.onclick = (event) => {
if (event.shiftKey) section.remove();
};
if (response.ok) {
section.innerHTML = markedUp(await response.text());
section.setAttribute("data-page", page);
history.pushState({}, "", `/${page}`);
} else {
section.innerHTML = "<p>This page doesn't exist (yet)</p>";
section.setAttribute("data-page", "404");
}
container.appendChild(section);
});
}
function markedUp(markdown) {
return marked.parse(wikiLinks(markdown));
}
function wikiLinks(markdown) {
return markdown.replace(
/\[\[([^\]]+)\]\]/g,
'<a href="$1" onclick="clickLink(event)">$1</a>'
);
}
function clickLink(event) {
event.preventDefault();
const page = event.target.innerText;
if (event.ctrlKey || event.metaKey) {
window.open(`/${page}`);
} else {
openPage(page, mouseX, mouseY);
}
}
window.clickLink = clickLink;
window.openPage = openPage;
let requestedDocument = window.location.pathname.replace(/^\/+/g, "");
if (requestedDocument == "") requestedDocument = "MainPage";
openPage(requestedDocument);
</script>
</body>
</html>