-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
68 lines (59 loc) · 1.9 KB
/
index.html
File metadata and controls
68 lines (59 loc) · 1.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css">
<style>
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
</style>
<title>Document</title>
</head>
<body>
<article id="main" class="markdown-body"></article>
</body>
<script>
class Main {
constructor() {
this.converter = new showdown.Converter()
this.main = document.getElementById("main")
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
this.page = params.page
}
convert(markdown) {
return this.converter.makeHtml(markdown)
}
getUrl() {
const host = `${window.location.protocol}//${window.location.host}/`
const path = `${window.location.pathname.split('/').slice(0, -1).join('')}/${this.page.toUpperCase()}.md`
return host + path
}
async run() {
const r = await fetch(this.getUrl())
const d = await r.text()
this.main.innerHTML = this.convert(d)
const c = document.querySelector("#main h1")
if (!!c) {
document.title = c.innerText
}
}
}
const m = new Main()
m.run()
</script>
</html>