1
0
dwelling-home/web/guestbook.templ

91 lines
3.6 KiB
Plaintext
Raw Permalink Normal View History

package web
import "fmt"
import "strconv"
import "strings"
2024-06-25 04:37:35 +04:00
import "time"
import "net/http"
import "github.com/invopop/ctxi18n/i18n"
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(i18n.T(ctx, "base.section.guestbook"), i18n.T(ctx, "guestbook.description"), "guestbook, personal", "/guestbook", r, guestbookHead()) {
<form id="new-post" action="/api/guestbook" method="POST">
<input type="text" name="name" maxlength="80" placeholder={ i18n.T(ctx, "guestbook.form.name") }/>
<input type="text" name="website" maxlength="255" placeholder={ i18n.T(ctx, "guestbook.form.website") }/>
<textarea name="message" maxlength="4096" placeholder={ i18n.T(ctx, "guestbook.form.message") } required></textarea>
<span class="checkboxes">
<input type="checkbox" name="hide_website" id="hide-website" checked/>
<label for="hide-website">{ i18n.T(ctx, "guestbook.form.hide-website-1") } <small>{ i18n.T(ctx, "guestbook.form.hide-website-2") }</small></label>
<br/>
<small>@templ.Raw(i18n.T(ctx, "guestbook.form.quote-usage", i18n.M{"sign":">"}))</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>@templ.Raw(i18n.T(ctx, "guestbook.form.captcha-validity", i18n.M{"valid":"<b>10</b>"}))</small>
</span>
<input type="submit" value={ i18n.T(ctx, "guestbook.form.send-post") }/>
</form>
<section id="posts">
for _, entry := range entries {
<article>
<header>
2024-09-15 15:09:55 +04:00
{{ created_tz := util.ToClientTimezone(entry.Created, r).Format("02.01.2006 15:04:05 -07:00") }}
{{ website := "" }}
if !entry.HideWebsite {
{{ website = entry.Website }}
}
{ strconv.FormatInt(entry.ID, 10) } { i18n.T(ctx, "guestbook.post.by") } <span class="highlighted">{ entry.Name }</span> <em>{ website }</em> { i18n.T(ctx, "guestbook.post.on") } <time datetime={ entry.Created.Format(time.RFC3339) }>{ created_tz }</time>
</header>
for _, line := range strings.Split(entry.Message, "\n") {
2024-06-25 04:37:35 +04:00
<p
if len(line) > 0 && line[0] == '>' {
2024-06-25 04:37:35 +04:00
class="quote"
}>{ line }</p>
}
if entry.Reply != nil {
<div class="reply">
<header>
2024-09-15 15:09:55 +04:00
{{ reply_created_tz := util.ToClientTimezone(entry.Reply.Created, r).Format("02.01.2006 15:04:05 -07:00") }}
{ i18n.T(ctx, "guestbook.post.reply") } <span class="highlighted">{ owner }</span> { i18n.T(ctx, "guestbook.post.on") } <time datetime={ entry.Reply.Created.Format(time.RFC3339) }>{ reply_created_tz }</time>
</header>
for _, line := range strings.Split(entry.Reply.Message, "\n") {
2024-06-25 04:37:35 +04:00
<p
if len(line) > 0 && line[0] == '>' {
2024-06-25 04:37:35 +04:00
class="quote"
}>@templ.Raw(line)</p>
}
</div>
}
</article>
}
if len(entries) == 0 {
<p class="center">{ i18n.T(ctx, "guestbook.post.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>
}