-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
191 lines (165 loc) · 6.39 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="Markdown documentation proof-of-concept using GitHub Pages, adapted from https://github.com/dandalpiaz/markdown-pages">
<title>Docs test</title>
<!-- favicon, originally from https://www.iconsdb.com/gray-icons/book-16-icon.html -->
<link rel="icon" type="image/x-icon" href="favicon.ico?v=1">
<!-- pre-connect to CDNs, also with crossorigin -->
<link rel="preconnect" href="https://cdnjs.cloudflare.com">
<link rel="preconnect" href="https://cdnjs.cloudflare.com" crossorigin>
<link rel="preconnect" href="https://unpkg.com">
<link rel="preconnect" href="https://unpkg.com" crossorigin>
<!-- convert Markdown to HTML using https://showdownjs.com/ -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js" integrity="sha512-LhccdVNGe2QMEfI3x4DVV3ckMRe36TfydKss6mJpdHjNFiV07dFpS2xzeZedptKZrwxfICJpez09iNioiSZ3hA==" crossorigin="anonymous"></script>
<!-- syntax highlighting for code blocks using https://highlightjs.org/ -->
<script src="https://unpkg.com/@highlightjs/[email protected]/highlight.min.js" integrity="sha512-gU7kztaQEl7SHJyraPfZLQCNnrKdaQi5ndOyt4L4UPL/FHDd/uB9Je6KDARIqwnNNE27hnqoWLBq+Kpe4iHfeQ==" crossorigin="anonymous"></script>
<!-- basic styles for page using https://picocss.com/ -->
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css" integrity="sha512-2MD814AVKlRmLMNeIKnmSSJEaI1gFz742oiIWCkRDZ3ZoN8lALOPN71gCCya8WItuZNfrulKl5jnLOVIhtGY+A==" crossorigin="anonymous">
<!-- page styles from https://github.com/dandalpiaz/markdown-pages July 20th 2022 -->
<style>
/* adjust contain widths */
@media (max-width: 1199px) {
.container {
max-width: 100%;
padding-left: 30px;
padding-right: 30px;
}
}
@media (max-width: 575px) {
.container {
padding-left: 16px;
padding-right: 16px;
}
}
/* increase code color contrast for a11y */
code {
color: rgb(135, 150, 160);
}
[data-theme="light"] code {
color: rgb(100, 125, 135);
}
/* keep link color for code links */
a code {
color: var(--code-tag-color) !important;
font-size: 0.8rem;
vertical-align: middle;
}
/* adjust heading margins */
h2 {
margin-bottom: 1.5rem;
}
/* dark/light mode toggle button */
#light-toggle {
position: absolute;
top: 10px;
right: 10px;
padding: 5px;
font-size: 14px;
font-weight: 500;
}
/* adjust syntax highlighting background */
[data-theme="dark"] .hljs {
background: rgb(24, 35, 44);
}
</style>
</head>
<body>
<main role="main" class="container">
<!-- toggle between dark & light mode -->
<a href="#" role="button" onclick="toggleLight();return false;" id="light-toggle" class="contrast">🌗 Light</a>
<!-- Markdown will be converted to HTML and inserted here -->
<div id="insert"></div>
</main>
<!-- script from https://github.com/dandalpiaz/markdown-pages, July 20th 2022 -->
<script type="text/javascript">
// set syntax highlighting theme based on light or dark mode
function setHighlightTheme(mode) {
var head = document.getElementsByTagName('HEAD')[0];
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
if (mode == "light") {
link.href = 'https://unpkg.com/@highlightjs/[email protected]/styles/atom-one-light.min.css';
}
if (mode == "dark") {
link.href = 'https://unpkg.com/@highlightjs/[email protected]/styles/monokai-sublime.min.css';
}
head.appendChild(link);
}
// toggle between light and dark mode
function toggleLight() {
var mode = localStorage.getItem("mode");
if (mode == "light") {
document.documentElement.setAttribute("data-theme", "dark");
document.getElementById('light-toggle').innerHTML = "🌗 Light";
localStorage.setItem("mode", "dark");
setHighlightTheme("dark");
}
if (mode == "dark" || mode == null) {
document.documentElement.setAttribute("data-theme", "light");
document.getElementById('light-toggle').innerHTML = "🌗 Dark";
localStorage.setItem("mode", "light");
setHighlightTheme("light");
}
}
// helper function to grab query string value
function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
// build URL for markdown file
var page = getParameterByName('page');
if (page) {
page = "pages/" + page + ".md"
} else {
// if no page specified, load "readme.md" (case sensitive)
page = "readme.md";
}
// request markdown file
var client = new XMLHttpRequest();
client.open('GET', page);
client.onreadystatechange = function() {
if (client.readyState == 4 && client.status == 200) {
if (client.responseText) {
var div = document.getElementById('insert');
div.innerHTML += client.responseText;
var conv = new showdown.Converter();
conv.setOption('tables', 'true');
conv.setOption('emoji', 'true');
conv.setOption('ghCompatibleHeaderId', 'true');
conv.setOption('simpleLineBreaks', 'true');
// convert markdown to HTML
document.getElementById('insert').innerHTML = conv.makeHtml(div.textContent);
// set title as first h1 plus site title
var h1s = document.getElementsByTagName("h1");
for (var i = 0; i < h1s.length; i++) {
var h1 = h1s[i];
document.title = h1.innerText + " | " + document.title;
}
// apply syntax highlighting for code blocks
hljs.highlightAll();
}
}
}
client.send();
// get current light/dark mode on page load
(function () {
var mode = localStorage.getItem("mode");
if (mode == "light") {
document.documentElement.setAttribute("data-theme", "light");
document.getElementById('light-toggle').innerHTML = "🌗 Dark";
setHighlightTheme("light");
} else {
setHighlightTheme("dark");
}
})();
</script>
</body>
</html>