1
0
dwelling-home/web/guestbook.templ

89 lines
3.2 KiB
Plaintext

package web
import "fmt"
import "strconv"
import "strings"
import "time"
import "net/http"
import "git.arav.su/Arav/justguestbook"
import "git.arav.su/Arav/dwelling-home/pkg/util"
templ Guestbook(captchaID, owner string, entries []*justguestbook.Entry, pageCount, pageCur int64, r *http.Request) {
@base("Guestbook", "This is my guestbook. Welcome.", "guestbook, personal", "/guestbook", r, guestbookHead()) {
<form id="new-post" action="/api/guestbook" method="POST">
<input type="text" name="name" maxlength="80" placeholder="Name (Anonymous if left blank)"/>
<input type="text" name="website" maxlength="255" placeholder="Website (optional)"/>
<textarea name="message" maxlength="4096" placeholder="Your message" required></textarea>
<span class="checkboxes">
<input type="checkbox" name="hide_website" id="hide-website" checked/>
<label for="hide-website">Hide website <small>(only I can see if set)</small></label>
<br/>
<small>Use &gt; to make a quote.</small>
</span>
<span class="captcha">
<input type="hidden" name="captcha_id" value={ captchaID }/>
<img src={ string(templ.URL(fmt.Sprintf("/api/captcha/%s/image", captchaID))) } alt="CAPTCHA" width="160" height="40"/>
<input type="text" name="captcha_answer" maxlength="6" placeholder="CAPTCHA" required/>
<small>Valid for <b>10</b> minutes.</small>
</span>
<input type="submit" value="Send a post"/>
</form>
<section id="posts">
for _, entry := range entries {
<article>
<header>
{{ created_tz := util.ToClientTimezone(entry.Created, r).Format("Monday _2 January 2006 15:04:05 -07:00") }}
{{ website := "" }}
if !entry.HideWebsite {
{{ website = entry.Website }}
}
{ strconv.FormatInt(entry.ID, 10) } by <span class="highlighted">{ entry.Name }</span> <em>{ website }</em> on <time datetime={ entry.Created.Format(time.RFC3339) }>{ created_tz }</time>
</header>
for _, line := range strings.Split(entry.Message, "\n") {
<p
if len(line) > 0 && line[0] == '>' {
class="quote"
}>{ line }</p>
}
if entry.Reply != nil {
<div class="reply">
<header>
{{ reply_created_tz := util.ToClientTimezone(entry.Reply.Created, r).Format("Monday _2 January 2006 15:04:05 -07:00") }}
Reply by <span class="highlighted">{ owner }</span> in <time datetime={ entry.Reply.Created.Format(time.RFC3339) }>{ reply_created_tz }</time>
</header>
for _, line := range strings.Split(entry.Reply.Message, "\n") {
<p
if len(line) > 0 && line[0] == '>' {
class="quote"
}>@templ.Raw(line)</p>
}
</div>
}
</article>
}
if len(entries) == 0 {
<p class="center">No posts.</p>
}
</section>
if pageCount > 1 {
<section id="pagination">
for n := int64(1); n <= pageCount; n++ {
{{ strN := strconv.FormatInt(n, 10) }}
if n == pageCur {
<span>&nbsp;{ strN }</span>
{{ continue }}
}
<a href={ templ.URL("/guestbook?p=" + strN) }>{ strN }</a>
}
</section>
}
}
}
templ guestbookHead() {
<link rel="stylesheet" href="/assets/css/guestbook.css"/>
<script src="/assets/js/captcha_refresh.js" defer></script>
}