From: Roberto Morado Date: Sun, 9 Nov 2025 23:17:48 +0000 (-0500) Subject: Initial commit X-Git-Url: https://git.morado.dev/post/static/gitweb.css?a=commitdiff_plain;h=1c94ad3019a67cfd88ce83d12185128bdec02ad3;p=blog.morado.dev Initial commit --- 1c94ad3019a67cfd88ce83d12185128bdec02ad3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a221964 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +deploy/ +posts/ +storage/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..43620bf --- /dev/null +++ b/README.md @@ -0,0 +1,154 @@ +# WitnessBlog + +Minimalist personal blog written for Deno. The app serves public Markdown posts, +protects an admin panel with username/password auth, persists data in Deno KV, +and mirrors everything to on-disk Markdown for easy versioning. + +## Features + +- Public homepage that lists every post (Markdown rendered with `marked`). +- Individual post pages with clean typography. +- Password-protected admin panel for creating new posts in Markdown. +- Posts are stored in Deno KV _and_ exported as Markdown files (front matter + + body). +- Session-based auth with HttpOnly cookies plus CSRF-protected admin forms. +- Markdown output is sanitized before serving to minimize XSS risk. +- CLI tooling for creating/listing/deleting users (`users.ts`). +- Sync utility (`sync_posts.ts`) to reconcile KV and the Markdown files. +- Basic unit/integration tests under `tests/`. + +## Requirements + +- [Deno](https://deno.com/runtime) 1.41+ with the `--unstable-kv` flag + available. +- Local filesystem access to write posts and KV files (default `./posts` and + `./storage`). + +## Project Layout + +``` +main.ts # HTTP server, routes, rendering, persistence helpers +sync_posts.ts # KV ↔️ Markdown sync utility +users.ts # CLI user management +posts/ # Markdown copies of every post (front matter + content) +storage/ # Deno KV data files +tests/ # Deno test suite +deploy/ # Server configs (nginx, systemd, git hooks) +``` + +## Running the Blog + +```sh +deno run --allow-net --allow-read --allow-write --unstable-kv main.ts +``` + +- Public site: http://localhost:8000/ +- Admin panel: http://localhost:8000/admin + +Before logging in you must create a user (see next section). New posts authored +in the admin UI are saved to both KV and `./posts/.md` automatically. + +## Managing Users + +`users.ts` provides interactive commands for managing accounts stored in KV. + +``` +deno run --allow-read --allow-write --unstable-kv users.ts +``` + +Available commands: + +| Command | Description | +| ------------------- | ----------------------------------------------------------- | +| `create` (default) | Interactive prompt for username + password (bcrypt hashed). | +| `list` | Displays every user with their creation timestamp. | +| `delete ` | Removes a user after confirmation. | +| `help` | Prints usage. | + +Example: + +```sh +deno run --allow-read --allow-write --unstable-kv users.ts list +deno run --allow-read --allow-write --unstable-kv users.ts delete alice +``` + +## Security Notes + +- Every login and admin form submission carries a CSRF token that must match the + HttpOnly `csrf_token` cookie issued when the page is rendered. +- Markdown is rendered with `marked` and then sanitized server-side so + `