aboutsummaryrefslogtreecommitdiff
path: root/views/layouts.templ
diff options
context:
space:
mode:
Diffstat (limited to 'views/layouts.templ')
-rw-r--r--views/layouts.templ57
1 files changed, 57 insertions, 0 deletions
diff --git a/views/layouts.templ b/views/layouts.templ
new file mode 100644
index 0000000..3db6f1b
--- /dev/null
+++ b/views/layouts.templ
@@ -0,0 +1,57 @@
+package views
+
+import (
+ "context"
+ "gitrepo.ru/neonxp/gorum/contextlib"
+ "gitrepo.ru/neonxp/gorum/models"
+)
+
+templ Layout() {
+ <!DOCTYPE html>
+ <html lang="ru">
+ <head>
+ <meta charset="utf-8"/>
+ <meta name="viewport" content="width=device-width, initial-scale=1"/>
+ <meta name="color-scheme" content="light dark"/>
+ <link rel="stylesheet" href={ "/assets/css/pico." + ctx.Value(contextlib.ThemeKey).(string) + ".min.css" }/>
+ <link rel="stylesheet" href="/assets/css/style.css" />
+ <title>Gorum</title>
+ </head>
+ <body>
+ <nav class="container-fluid">
+ <ul>
+ <li>
+ <strong>Gorum BBS</strong>
+ </li>
+ <li>
+ <a href="/">Список тем</a>
+ </li>
+ </ul>
+ <ul>
+ if isAuthorized(ctx) {
+ // <li><a href="/topic/new">Новая тема</a></li>
+ <li>{ getUser(ctx).Username }</li>
+ <li><form action="/logout" method="POST"><input type="submit" value="Выход"/></form></li>
+ } else {
+ <li><a href="/login">Вход</a></li>
+ <li><a href="/register">Регистрация</a></li>
+ }
+ </ul>
+ </nav>
+ <main class="container">
+ { children... }
+ </main>
+ <footer class="container-fluid">
+ <small>Работает на <a href="https://gorum.tech/">Gorum</a>.</small>
+ </footer>
+ </body>
+ </html>
+}
+
+func isAuthorized(ctx context.Context) bool {
+ _, authorized := ctx.Value(contextlib.UserKey).(models.User)
+ return authorized
+}
+func getUser(ctx context.Context) models.User {
+ return ctx.Value(contextlib.UserKey).(models.User)
+}