index.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package web
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "github.com/a-h/templ"
  7. "github.com/TecharoHQ/anubis/lib/challenge"
  8. "github.com/TecharoHQ/anubis/lib/config"
  9. "github.com/TecharoHQ/anubis/lib/localization"
  10. )
  11. func Base(title string, body templ.Component, impressum *config.Impressum, localizer *localization.SimpleLocalizer) templ.Component {
  12. return base(title, body, impressum, nil, nil, localizer)
  13. }
  14. func BaseWithChallengeAndOGTags(title string, body templ.Component, impressum *config.Impressum, challenge *challenge.Challenge, rules *config.ChallengeRules, ogTags map[string]string, localizer *localization.SimpleLocalizer) templ.Component {
  15. return base(title, body, impressum, struct {
  16. Rules *config.ChallengeRules `json:"rules"`
  17. Challenge any `json:"challenge"`
  18. }{
  19. Challenge: challenge,
  20. Rules: rules,
  21. }, ogTags, localizer)
  22. }
  23. func ErrorPage(msg, mail, code string, localizer *localization.SimpleLocalizer) templ.Component {
  24. return errorPage(msg, mail, code, localizer)
  25. }
  26. func Bench(localizer *localization.SimpleLocalizer) templ.Component {
  27. return bench(localizer)
  28. }
  29. func honeypotLink(href string) templ.Component {
  30. return templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
  31. fmt.Fprintf(w, `<script type="ignore"><a href="%s">Don't click me</a></script>`, href)
  32. return nil
  33. })
  34. }