guestbook, from cmkat.com/materials

a guestbook for a static site on cloudflare pages, stored in workers kv.

  functions/api/guestbook.js   the backend
  lib/message-board.js         shared storage and spam checks
  guestbook.js                 the page script
  guestbook-preview.js         newest entries on another page (optional)
  guestbook.html               the markup the script expects

setup
  1. put functions/ and lib/ in the root of your pages project.
  2. create a kv namespace and bind it to the project as GUESTBOOK.
  3. add GB_SALT (any long random string) and, optionally, GB_ADMIN (a secret
     token for deleting entries).
  4. optional captcha: TURNSTILE_SITEKEY and TURNSTILE_SECRET.
  5. redeploy.

messages can be 1,500 characters. timestamps include seconds and timezone.

spam rules (options in functions/api/guestbook.js): hidden honeypot field, 3 second
minimum, no links, length limits, one post a minute and five a day per visitor,
no exact repeats. ips are hashed, never stored. entries are always shown as text.

delete an entry:
  curl -X DELETE -H "Authorization: Bearer YOUR_GB_ADMIN" "https://yoursite/api/guestbook?id=ENTRY_ID"

free for personal, non-commercial sites.
