This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
html.go
149 lines (123 loc) · 3.52 KB
/
html.go
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
package main
const Template = `<!doctype html>
<html>
<head>
<title>Wiki</title>
<meta charset="utf-8" />
<style type="text/css">
body {
margin: 1rem;
font-family: georgia;
font-size: 0.9rem;
}
pre {
font-size: 1rem;
margin: 0;
padding 0;
}
ul {
list-style-type: square;
list-style-position: inside;
padding-left: 1rem;
}
hr {
height: 1px;
border: none;
border-bottom: 1px #eee solid;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: 'Helvetica Neue', georgia;
font-weight: 200;
}
.commit {
cursor: pointer;
background-color: #eee;
margin: 0.2rem 0;
padding: 0.2rem;
}
.highlight .gi > .x {
background-color: #eaffea;
color: #55a532;
}
.highlight .gd > .x {
background-color: #ffecec;
color: #bd2c00;
}
.highlight {
margin: 0.5rem 0;
border-left: 3px solid #eee;
padding-left: 0.5rem;
}
.date,
.hash,
.author,
.subject {
display: inline-block;
text-overflow: ellipsis;
margin: 0.1rem 0;
}
</style>
{{ if .CustomCSS }}
<link rel="stylesheet" href="/css/custom.css" type="text/css">
{{ end }}
</head>
<body>
<header>{{ .Title }}</header>
<section>{{ .Body }}</section>
<hr>
<footer class="commits">
{{ range .Commits }}
<div class="commit" data-hash="{{ .Hash }}" data-file="{{ .FileNoExt }}">
<span class="date">{{ .HumanDate }}</span> ·
<span class="author">{{ .Author }}</span> ·
<span class="subject">{{ .Subject }}</span>
<div class="diff"></div>
</div>
{{ end}}
</footer>
<script>
(function() {
var commits = document.querySelectorAll('.commit');
function closeDiffs(skipElement) {
var diffs = document.querySelectorAll('.diff');
for (var i = 0; i < diffs.length; i++) {
if (skipElement && skipElement === diffs[i]) {
continue;
}
diffs[i].innerHTML = '';
}
}
function request(dataset, callback) {
var url = '/api/diff/' + dataset.hash + '/' + dataset.file;
var r = new XMLHttpRequest();
r.onreadystatechange = function() {
if (r.readyState === 4 && r.status === 200) {
callback(r.responseText);
}
};
r.open('GET', url, true);
r.send(null);
}
function onClick() {
var diff = this.querySelector('.diff');
if (diff.innerHTML === "") {
request(this.dataset, function(response) {
diff.innerHTML = response;
});
} else {
closeDiffs();
}
closeDiffs(diff);
}
for (var i = 0; i < commits.length; i++) {
commits[i].addEventListener('click', onClick);
}
})();
</script>
</body>
</html>`