summaryrefslogtreecommitdiff
path: root/index.templ
blob: 5da5272f68a18cfc09b6a78f9d96c6d2b65b335c (plain)
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
package main

import "fmt"
import "time"
import "net/url"

templ index(ps []Post) {
	<!DOCTYPE html>
	<html>
		<head>
			<meta charset="utf-8"/>
			<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
			<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
			<script src="/static/htmx.min.js"></script>
			<link rel="preload" href="/static/style.css" as="style"/>
			<link rel="stylesheet" href="/static/style.css"/>
		</head>
		<body>
			<div id="container">
				<div id="header">
					<h2>Tinygram</h2>
				</div>
				<div id="posts">
					@posts(ps)
				</div>
			</div>
		</body>
	</html>
}

templ posts(posts []Post) {
	for _, post := range posts {
		<div class="post">
			<img src="/static/firstpost.png" alt={ post.ImageID }/>
			<div class="summary">
				<p class="description">{ post.Description }</p>
				<p class="date">{ post.CreatedAt.Format("2006-01-02 - 15:04") }</p>
			</div>
		</div>
	}
	if len(posts) > 0 {
		<div
			style="min-height:1px"
			hx-get={ fmt.Sprintf("/posts?after=%v", url.QueryEscape(posts[len(posts)-1].CreatedAt.Format(time.RFC3339))) }
			hx-target="#posts"
			hx-trigger="revealed"
			hx-swap="beforeend"
		></div>
	}
}