summaryrefslogtreecommitdiff
path: root/index.templ
diff options
context:
space:
mode:
authorSamuel W <samuel.wilhelmsson@gmail.com>2024-01-30 21:38:24 +0100
committerSamuel W <samuel.wilhelmsson@gmail.com>2024-01-30 21:38:24 +0100
commit34f9aa54e2d67a54496606591c8ca5fcfef597f6 (patch)
treed653dcf2e209fa9524455b26a5681578f13c0b90 /index.templ
downloadtinygram-34f9aa54e2d67a54496606591c8ca5fcfef597f6.tar.gz
tinygram-34f9aa54e2d67a54496606591c8ca5fcfef597f6.zip
init commit
Diffstat (limited to 'index.templ')
-rw-r--r--index.templ50
1 files changed, 50 insertions, 0 deletions
diff --git a/index.templ b/index.templ
new file mode 100644
index 0000000..5da5272
--- /dev/null
+++ b/index.templ
@@ -0,0 +1,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>
+ }
+}