Split compose dev/prod and relax contact form friction.

Use compose.dev.yaml and compose.prod.yaml with fixed Go cache mounts, block sudo make dev, build Air outside app/tmp for rootless Docker, soften English spam checks, and simplify contact error copy.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-07 11:41:13 +12:00
parent 3f5235daaf
commit bf110d0bc7
13 changed files with 125 additions and 76 deletions

View File

@@ -2,8 +2,8 @@ root = "."
tmp_dir = "tmp"
[build]
cmd = "templ generate --notify-proxy && go build -o ./tmp/main ./cmd/server"
entrypoint = ["./tmp/main"]
cmd = "templ generate --notify-proxy && go build -o /tmp/website-dev-main ./cmd/server"
entrypoint = ["/tmp/website-dev-main"]
delay = 300
exclude_dir = ["tmp", "bin", "images", "vendor", "testdata"]
exclude_regex = ["_templ.go"]

View File

@@ -75,7 +75,7 @@ func Parse(name, email, message string) (Submission, Errors) {
case errors.Is(err, contactcheck.ErrName):
errs["name"] = "Name is too long."
case errors.Is(err, contactcheck.ErrNotEnglish):
errs["message"] = "This site only accepts messages written in English. If your message is in English, try adding a few more clear sentences so we can detect the language reliably."
errs["message"] = "Please write your message in English."
default:
errs["message"] = "Could not accept this message."
}

View File

@@ -12,6 +12,9 @@ const (
minMessageRunes = 20
maxMessageRunes = 8000
maxNameRunes = 120
// Reject non-English only when the detector is fairly confident.
englishRejectConfidence = 0.80
)
var (
@@ -38,13 +41,15 @@ func ValidateEnglish(name, message string) error {
combined := strings.TrimSpace(name) + "\n\n" + msg
info := whatlanggo.Detect(combined)
// Block clearly non-Latin scripts (CJK, Cyrillic, etc.).
if info.Script != nil && info.Script != unicode.Latin {
return ErrNotEnglish
}
if info.Lang != whatlanggo.Eng {
// Allow uncertain detection; block only confident non-English.
if info.Lang != whatlanggo.Eng && info.IsReliable() {
return ErrNotEnglish
}
if !info.IsReliable() && info.Confidence < 0.55 {
if info.Lang != whatlanggo.Eng && info.Confidence >= englishRejectConfidence {
return ErrNotEnglish
}
return nil

View File

@@ -0,0 +1,29 @@
package contactcheck
import "testing"
func TestValidateEnglish_acceptsPlainEnglish(t *testing.T) {
if err := ValidateEnglish("Jimmy", "Hello, I need help with an LED install."); err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
func TestValidateEnglish_acceptsTechnicalEnglish(t *testing.T) {
msg := "Need a quote for 50m WS2812 strip + ESP32 controller in Auckland."
if err := ValidateEnglish("Alex", msg); err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
func TestValidateEnglish_rejectsNonLatinScript(t *testing.T) {
msg := "これは日本語のテストメッセージです。十分な長さがあります。"
if err := ValidateEnglish("Jimmy", msg); err != ErrNotEnglish {
t.Fatalf("got %v, want ErrNotEnglish", err)
}
}
func TestValidateEnglish_rejectsTooShort(t *testing.T) {
if err := ValidateEnglish("Jimmy", "Hi there"); err != ErrTooShort {
t.Fatalf("got %v, want ErrTooShort", err)
}
}

View File

@@ -9,17 +9,18 @@ import (
const HoneypotField = "website"
// MinFormFillDuration is the minimum time between showing the form and submit.
const MinFormFillDuration = 3 * time.Second
const MinFormFillDuration = 5 * time.Second
// SpamHoneypot reports whether the honeypot was filled (likely spam).
func SpamHoneypot(value string) bool {
return strings.TrimSpace(value) != ""
}
// FormFilledTooFast reports whether the form was submitted before seenUnix (0 = never seen).
// FormFilledTooFast reports whether the form was submitted before seenUnix.
// Missing timing data (seenUnix <= 0) is allowed — honeypot and rate limits still apply.
func FormFilledTooFast(seenUnix int64, now time.Time) bool {
if seenUnix <= 0 {
return true
return false
}
return now.Sub(time.Unix(seenUnix, 0)) < MinFormFillDuration
}

View File

@@ -18,8 +18,8 @@ func TestFormFilledTooFast(t *testing.T) {
now := time.Unix(1_000_000, 0)
seen := now.Add(-MinFormFillDuration).Unix()
if !FormFilledTooFast(0, now) {
t.Error("missing seen time should be too fast")
if FormFilledTooFast(0, now) {
t.Error("missing seen time should be allowed")
}
if !FormFilledTooFast(seen+1, now) {
t.Error("submit before min duration should be too fast")

View File

@@ -4,13 +4,11 @@ templ ContactForm(enabled bool) {
<section id="contact" class="contact">
<h2>Contact</h2>
<p class="contact-intro">
Interested in a project or collaboration? Send a message below. Messages must be in English.
Interested in a project or collaboration? Send a message below.
</p>
if !enabled {
<p class="contact-unavailable">
The contact form is not configured yet. Email
<a href="mailto:hello@technical.kiwi">hello@technical.kiwi</a>
directly.
The contact form is not configured yet.
</p>
} else {
<form
@@ -33,7 +31,7 @@ templ ContactForm(enabled bool) {
</div>
<div class="form-row">
<label for="message">Message</label>
<textarea id="message" name="message" required minlength="20" rows="6" maxlength="8000" placeholder="Write at least a few sentences in English."></textarea>
<textarea id="message" name="message" required minlength="20" rows="6" maxlength="8000" placeholder="Tell us about your project or question."></textarea>
</div>
<input
class="hp-field"
@@ -70,8 +68,7 @@ templ ContactValidationAlert(errs map[string]string) {
templ ContactSendError() {
<div class="alert alert-error" role="alert">
<p>Something went wrong sending your message. Please try again later or email
<a href="mailto:hello@technical.kiwi">hello@technical.kiwi</a>.</p>
<p>Something went wrong sending your message. Please try again later.</p>
</div>
}