-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·148 lines (116 loc) · 5.09 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
<!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">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<!-- favicon from: https://iconscout.com/contributors/twitter-inc , thanks! -->
<link rel="shortcut icon" href="favicon.svg">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Remarked: The Simplest Markdown Site Maker (maybe)</title>
<!-- Javascript -->
<script src="libs/jquery-3.1.1.min.js"></script>
<script src="libs/popper.min.js"></script>
<script src="libs/bootstrap.bundle.min.js"></script>
<script src="libs/marked.min.js"></script>
<!-- CSS -->
<link rel="stylesheet" href="libs/bootstrap.min.css">
<link rel="stylesheet" href="styles.css">
<script>
var x = 100 //just for demo purposes
var homepage = 'Home.md' //where you want to start from
window.onhashchange = function() {
var hash = window.location.hash.replace("#", "")
if (hash!=''){
//console.log("hash:", hash)
loadPage(hash)
}else{
//console.log(window.location)
loadPage(homepage)
}
}
function loadPage(markdownFileName) {
console.log("loadPage:", markdownFileName)
$.get(markdownFileName, function (data) {
html = myParse(data, markdownFileName)
$('#content').html(html);
}, 'text');
document.title = decodeURIComponent(markdownFileName.replace(".md", ""))
window.location.hash = `${markdownFileName}`;
}
/* Turns markdown links and images into HTML links and images*/
function fixLinks(markdownContent) {
var regex = /(\!\[([^\[\]]+)\]\(([^\)]+)\))|(\[([^\[\]]+)\]\(([^\)]+)\))/g; //find markdown images and links.
let match;
while ((match = regex.exec(markdownContent)) !== null) {
if (match[1]) {
var text = match[2];
var link = match[3];
/*console.log("Type: Image", text, link);*/
markdownContent = markdownContent.replace(`![${text}](${link})`, `<img src="${link}" alt="${text}">`)
} else {
var text = match[5];
var link = match[6];
/*console.log("Type: Link", text, link);*/
if (link.startsWith("http")){
markdownContent = markdownContent.replace(`[${text}](${link})`, `<a href="${link}" target="_blank">${text}</a>`)
}else{
link = link.replace("../", '') //fix "backup relative links"
markdownContent = markdownContent.replace(`[${text}](${link})`, `<a href="javascript:loadPage('${link}')">${text}</a>`)
}
}
}
return markdownContent
}
function myParse(data) {
// maybe get any meta data from the page at this point?
data = fixLinks(data)
var html = marked.parse(data) // Use the marked.js lib to turn markdown into HTML
return html
}
</script>
</head>
<body>
<div class="jumbotron text-center">
<h1><a href="javascript:loadPage( 'Home.md') "><img src="favicon.svg" width="100" alt="logo">Remarked Home</a></h1>
<p>This single web page makes navigating a folderful of Markdown files possible - so simple!</p>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div id="content"> Your Home.md will be shown here. If it's not, maybe you opened this
HTML file rather than loading it from a server (which means jquery get() function
falls foul of CORS policies).
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
Footer <span id="permalink"></span>
</div>
</footer>
<script>
//When the page has finished loading.... load your homepage
$(document).ready(function () {
//this could maybe look at search args to replace the homepage.
if (window.location.hash){
var file = window.location.hash.replace("#", "")
console.log(`file: ${file}`)
if ( file != null && file.endsWith('.md') ){
homepage = file
}
}
$.get(homepage, function (data) {
// console.log(data)
html = myParse(data)
//console.log("html:", html)
$('#content').html(html);
}, 'text');
});
</script>
</body>
</html>