Automatically generated from the Gemini capsule gemini://l-3.space

Time-stamp: <2026-05-04 13h50 UTC>

Keeping track of thoughts.md as a webpage

I realise that this is not exactly in the spirit of the smol web, and i have yet to decide on way to make this accessible over gemini, but here's a quick solution i found to scratch an itch i had.

The "problem"

I have a file called `thoughts.md` on my laptop, where i keep track of things that i ought to write down™ lest they become eroded by steady march of entropy, so that i have a central place where i can forget about things. But, and this is important, that file is on my laptop --- only.

What if it wasn't?

Enter python, bottle, nginx, systemd

As i'm already hosting a website, what about a quick and dirty script that served a webpage with a textarea, and loaded the latest %YYYYMMDDHHMMSS.md file from a directory. If the user posts with "save", then make a new file.

There are many, many features that this could grow, but for now having a text area i can reach from anyway, behind some auth'd endpoint from anywhere is all that i need.

Implementation details

This takes a tiny amount of glue, but here's the basic idea

[Unit]
Description=Note server
After=network.target

[Service]
Type=simple
DynamicUser=yes
StateDirectory=notes
WorkingDirectory=/var/lib/private/notes
ExecStart=/usr/bin/python3 /usr/local/bin/note.py /var/lib/private/notes --host 127.0.0.1 --port NNN-CHANGE-ME
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

location /CHANGE-ME-XXX {
    rewrite ^/CHANGE-ME-XXX/?(.*)$ /$1 break;
    proxy_pass         http://127.0.0.1:18088;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;

    auth_basic         "notes";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

#!/usr/bin/env python3
import argparse
import re
from datetime import datetime
from pathlib import Path

import bottle
from bottle import request, run


def latest_file(directory: Path) -> Path | None:
    files = [p for p in directory.glob("*.md") if re.match(r"^\d{14}\.md$", p.name)]
    return max(files, key=lambda p: p.stat().st_mtime) if files else None


def save(directory: Path, text: str) -> Path:
    filename = f"{datetime.now():%Y%m%d%H%M%S}.md"
    path = directory / filename
    _ = path.write_text(text, encoding="utf-8")
    return path


def make_page(directory: Path) -> str:
    latest = latest_file(directory)
    content = latest.read_text(encoding="utf-8") if latest else ""
    filename = latest.name if latest else "(none)"
    return f"""<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>notes</title>
<style>
body {{ max-width: 800px; margin: 2em auto; padding: 0 1em; font-family: system-ui, sans-serif; }}
.meta {{ color: #666; font-size: 0.85em; margin-bottom: 1em; }}
textarea {{ width: 100%; height: 75vh; font-family: monospace; font-size: 14px; padding: 0.5em; }}
button {{ padding: 0.4em 1.2em; margin-top: 0.5em; }}
</style>
</head>
<body>
<div class="meta">latest: {filename}</div>
<form method="POST" action="save">
<textarea name="text" spellcheck="true">{bottle.html_escape(content)}</textarea>
<br><button>save</button>
</form>
</body>
</html>"""


def main():
    parser = argparse.ArgumentParser(description="note server")
    parser.add_argument("directory", type=Path, help="where to store .md files")
    parser.add_argument("--host", default="127.0.0.1")
    parser.add_argument("--port", type=int, default=8080)
    args = parser.parse_args()

    args.directory.mkdir(parents=True, exist_ok=True)

    @bottle.route("/")
    def index():
        return make_page(args.directory)

    @bottle.route("/save", method="POST")
    def save_route():
        text = request.forms.get("text", "")
        path = save(args.directory, text)
        return make_page(args.directory)

    run(host=args.host, port=args.port)


if __name__ == "__main__":
    main()