blob: b8a3a742822f4a79662498c0a52703a4b846f8c8 (
plain) (
blame)
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
|
{{define "list-content"}}
<h1>Posts</h1>
{{if .Posts}}
<table>
<thead>
<tr>
<th>Title</th>
<th>Date</th>
<th>Tags</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
{{range .Posts}}
<tr>
<td>{{.Title}}</td>
<td>{{.Date}}</td>
<td>
{{if .Tags}}
<div class="tags">
{{range .Tags}}<span class="tag">{{.}}</span>{{end}}
</div>
{{end}}
</td>
<td>
{{if .Draft}}<span class="badge badge-draft">Draft</span>{{else}}<span class="badge badge-published">Published</span>{{end}}
</td>
<td>
<div class="actions">
<a href="/admin/{{.Slug}}" class="btn btn-secondary">Edit</a>
<button class="btn btn-danger" onclick="deletePost('{{.Slug}}', '{{.Title}}')">Delete</button>
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
{{else}}
<div class="empty">No posts yet. <a href="/admin/new">Create one.</a></div>
{{end}}
<script>
function deletePost(slug, title) {
if (!confirm('Delete "' + title + '"?')) return;
fetch('/admin/' + slug, { method: 'DELETE' })
.then(() => window.location.href = '/admin/')
.catch(err => alert('Delete failed: ' + err));
}
</script>
{{end}}
|