catbase/bot/web/index.templ

96 lines
2.3 KiB
Plaintext
Raw Normal View History

2024-02-27 19:29:54 +00:00
package web
2024-02-28 19:32:28 +00:00
import "fmt"
2024-02-27 19:29:54 +00:00
templ (w *Web) Header(title string) {
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
/>
<style>
.navTitle {
text-style: none;
color: var(--pico-h1-color);
}
input:invalid {
border: 2px dashed red;
}
button {
padding: 5px;
}
</style>
2024-02-27 19:29:54 +00:00
<meta charset="UTF-8" />
if title != "" {
2024-02-28 15:43:24 +00:00
<title>{ w.botName() } - { title }</title>
2024-02-27 19:29:54 +00:00
} else {
2024-02-28 15:43:24 +00:00
<title>{ w.botName() }</title>
2024-02-27 19:29:54 +00:00
}
</head>
}
templ (w *Web) Footer() {
<script src="//unpkg.com/htmx.org@1.9.10" integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC" crossorigin="anonymous"></script>
}
templ (w *Web) Index(title string, contents templ.Component) {
<!DOCTYPE html>
<html lang="en" class="no-js">
2024-02-27 19:29:54 +00:00
@w.Header(title)
<body>
@w.Nav(title)
<main class="container-fluid">
if contents != nil {
@contents
}
</main>
2024-02-27 19:29:54 +00:00
<footer>
@w.Footer()
</footer>
2024-02-27 19:29:54 +00:00
</body>
</html>
}
templ (w *Web) Nav(currentPage string) {
<header>
<nav style="margin-right: 2em; margin-left: 2em">
<ul>
<li><strong><a href="/" class="navTitle">{ w.botName() }</a></strong></li>
</ul>
<ul>
for _, item := range w.GetWebNavigation() {
<li>
if currentPage == item.Name {
<a class="is-active" aria-current="page" href={ templ.URL(item.URL) }>{ item.Name }</a>
} else {
<a href={ templ.URL(item.URL) }>{ item.Name }</a>
}
</li>
}
</ul>
</nav>
</header>
2024-02-27 19:29:54 +00:00
}
2024-02-28 19:32:28 +00:00
templ (w *Web) showStats() {
<h2>Stats</h2>
<table>
<tr>
<td>Messages Seen</td>
<td>{ fmt.Sprintf("%d", w.stats.MessagesRcv) }</td>
</tr>
<tr>
<td>Messages Sent</td>
<td>{ fmt.Sprintf("%d", w.stats.MessagesSent) }</td>
</tr>
<tr>
<td>Uptime</td>
2024-02-28 22:05:23 +00:00
<td>{ w.stats.Uptime() }</td>
2024-02-28 19:32:28 +00:00
</tr>
</table>
}