Modules
Claps
1 min read
The claps module adds a clap button to any page. Counts are stored in Cloudflare KV for fast reads, pre-built to a static JSON file at build time, and updated by a lightweight Worker handler.
Installation
pnpm add @stedefast/module-claps
Setup
// stedefast.config.ts
import { defineConfig } from "@stedefast/core";
import { ClapsModule } from "@stedefast/module-claps";
export default defineConfig({
// ...
modules: [
ClapsModule({
maxClapsPerPage: 50, // default: 50 — per-user limit stored in localStorage
}),
],
cloudflare: {
projectName: "my-site",
kvNamespaces: [{ binding: "CLAPS_KV", namespaceId: "YOUR_KV_NAMESPACE_ID" }],
},
});
Cloudflare bindings
Create a KV namespace:
wrangler kv namespace create CLAPS_KV
Copy the id into your config.
Using the island in a template
<div
data-island="ClapsIsland"
data-props={JSON.stringify({ pageId: page.slug })}
/>
The island loads dist/data/claps/counts.json, shows the count for the current page immediately, and updates optimistically when clicked. Each user's clap count is tracked in localStorage to enforce maxClapsPerPage.
How it works
- Build time —
buildStaticExport()reads all KV keys with prefixclaps:and writesdist/data/claps/counts.json - Page load — Island fetches
/data/claps/counts.jsonfrom CDN, renders count immediately - Clap —
POST /_modules/claps/clapincrements the KV counter - Next build — Static JSON is regenerated with updated counts
Configuration reference
| Option | Type | Default | Description |
|---|---|---|---|
maxClapsPerPage |
number |
50 |
Maximum claps a single user can give to one page |