summaryrefslogtreecommitdiffstats
path: root/templates/post.html
blob: 10c51ee6564052f367668437f118eacb355090ac (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
{{define "post.html"}}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{{.Title}}</title>
  <link rel="stylesheet" href="/assets/styles/main.css">
  <script type="importmap">
  {
    "imports": {
      "shared": "/assets/lib/shared.js",
      "thumbhash": "/assets/lib/dist/build.js"
    }
  }
  </script>
  {{- range .ComponentScripts}}
  <script type="module" src="{{.}}"></script>
  {{- end}}
</head>

<body>
  <a id="edit-link" href="/admin{{.Path}}" hidden>Edit</a>
  <main>
    <time>{{.Date}}</time>
    {{.Content}}
  </main>
  <script type="module">
    import { thumbHashToDataURL } from 'thumbhash'
    for (const fig of document.querySelectorAll('figure[data-thumbhash]')) {
      const bytes = Uint8Array.from(atob(fig.dataset.thumbhash), c => c.charCodeAt(0))
      fig.style.backgroundImage = `url(${thumbHashToDataURL(bytes)})`
      fig.style.backgroundSize = 'cover'
      const img = fig.querySelector('img')
      if (img) img.addEventListener('load', () => { fig.style.backgroundImage = '' }, { once: true })
    }
  </script>
  <script>
    fetch('/admin/ping', {credentials: 'include'})
      .then(r => { if (r.ok) document.getElementById('edit-link').hidden = false; })
      .catch(() => {});
  </script>
</body>

</html>
{{end}}