Writing from a phone
The trick is that a bare filename in an image line resolves against the incoming/ staging directory:
- Shoot a photo, upload it via any SFTP client into
<repo>/incoming/(setup: Getting started). - SSH into the server,
./blog.sh add, and write-- no path. - If the photo hasn't finished uploading yet, the CLI waits and re-checks on Enter instead of failing.
- On save the photo is copied into
media.nosync/<year>/<slug>/and itsincoming/copy is removed -- an emptyincoming/means nothing is pending. - Editing that post later doesn't need the photo again: a bare filename is looked for in the post's own
media.nosync/<year>/<slug>/first and inincoming/only after that, so a file that's already been saved resolves without any upload (and without being copied again).
iPhones photograph in HEIC by default, which only Safari can display. Attaching one stops the save with the exact conversion command -- or, with media.convert_heic: true in config/site.yml, the engine converts it to JPEG itself during the save (detected by content, so a HEIC named .jpg is caught too; AVIF, which browsers do display, is left alone). The simplest fix is on the phone itself: Settings → Camera → Formats → Most Compatible.
A photo's GPS position never reaches the site. Saving strips the place of capture from the file's metadata (media.strip_location, on unless config/site.yml turns it off -- the notes there say why); the camera, the moment and the orientation stay. ./blog.sh doctor --strip-location cleans photos saved before the engine did this -- the only thing doctor ever writes.
Video from the same phone is mentioned, not refused. The same setting decides the codec, and the save says one line when it matters: that a clip is HEVC (most browsers play it, the rest show an empty player), or that it is a QuickTime .mov (the video inside is usually ordinary H.264, but not every browser accepts the container). Both come with the ffmpeg command that fixes them -- re-encoding for the codec, repacking for the container, which copies the video across untouched. A third line is about neither: a video whose index sits at the end of the file, which is where a recorder has to put it, and which makes a reader wait for the whole download before the first frame appears. The same repack moves it to the front.
media: remux_video: true has the engine do that repack itself, when ffmpeg is on the machine -- index to the front, .mov to .mp4, the picture and the sound copied across untouched, about a second for a phone video. Every video and sound track comes across, not just the first of each, and so does the recording time; the metadata tracks an iPhone adds to a .mov do not, because an MP4 has nowhere to keep them. It is off by default, like the HEIC conversion, because it shells out to a tool the engine does not ship. Unlike the HEIC conversion it never refuses: no ffmpeg, or a repack that will not go through, and the post is saved with the file as it arrived and the sentence the author would have had anyway. A video in the wrong wrapper still plays for nearly everybody; a HEIC photo does not.
The post is saved either way; the only hard stop for a video is the per-file size limit, and a long 4K clip reaches that on its own -- a phone clip out of the share sheet runs about 1.3 MB a second, so the 24 MB default is roughly seventeen seconds of it. A longer one wants a smaller size chosen on the phone before it is sent.
Handing over a whole file
Every step above is a conversation: the CLI opens an editor, waits for a photo, asks what to do with the draft. ./blog.sh add <file> is the same work with the conversation removed -- it takes a markdown file with the usual header, writes the draft, and returns. It never asks anything, so it is the route for a shortcut, a script or anything else running where nobody is at the keyboard. The file is read as the editor's buffer is: a line starting with // is a note to yourself and does not reach the post (//--more--// is the one that does, and a // inside a code fence is the code), and neither does a <!-- ... --> block.
./blog.sh add clanek.md
A bare name -- one with no slash in it -- is looked for in incoming/, so the file can arrive by the same upload as the photos. Anything else is a path and is used as given, relative to wherever you were standing. A file that came out of incoming/ is deleted once the post is written -- the photos already work that way, and an empty incoming/ is what says nothing is pending. A file outside incoming/ is never touched: on a Mac that is quite possibly the only copy. The rule is about where the file is, not how you named it, so ./blog.sh add "$PWD/incoming/x.md" tidies up after itself like any other upload.
Where the wizard would ask, this refuses instead, and writes nothing:
- a photo that has not finished uploading -- the wizard waits and re-checks on Enter; here there is nobody to wait for, so the missing names are printed and the post is not written. Upload them and run it again.
- an empty body, a file that is not text, a file this account cannot read, something that is not a file at all, an option the command does not have, or a second filename (one file, one post -- a name silently dropped is a post a looping script thinks it made).
It stops at the draft. The file says write this down, not put it in front of the world -- publishing stays a second command:
./blog.sh publish <slug> --yes
--yes answers the draft dialog with "publish" in advance. --json, which needs --yes beside it, prints the same object add --json does -- ok, slug, path, state, scheduled, date, url, deploy, warnings, the keys every action on a post answers with -- or a refusal with its reason as a code (not_found, already_published, publish_refused), and leaves with zero either way, for the reason add does: a phone throws away the output of a command that failed. --no-announce publishes the page and sends nothing to Mastodon or Bluesky; it works with or without --yes, and because nothing was attempted, ./blog.sh toot <slug> can still send the announcement by hand afterwards. (It does not travel into a scheduled publish -- the cron works from the post itself and will announce it when its date arrives; the run says so if you schedule under the flag.)
One question --yes will not answer for you: a post dated outside the recent window is published but not announced, and the run says so. Announcing is the one step that cannot be taken back. Two more it refuses rather than guesses: --yes needs the slug spelled out (without one, publish offers the drafts to pick from, and picking belongs with the preview in front of you), and it will not choose between two posts sharing a slug in different years -- it names the years and stops.
--json turns the answer into data -- one object on standard output and nothing else, so a caller can read it without parsing prose:
{
"slug": "psano-v-posteli",
"path": "/home/me/blog/content.nosync/posts/2026/psano-v-posteli.json",
"state": "draft",
"url": "https://example.com/draft/89260b63fb498e75/psano-v-posteli/",
"deploy": "done",
"warnings": []
}
Every key is always there. deploy is done when the site is already carrying the draft and pending when it owes an upload that the next scheduled run will finish -- the difference between "open this address now" and "open it shortly". warnings collects everything the run said for itself, which on this route is the only place to hear it: a photo over the size limit, a video whose container some browsers refuse, a HEIC that was converted. url is empty rather than half an address when the site has no base_url yet, and the reason is in warnings. The exit code is 0 or 1, nothing else. A refusal answers in the same place and leaves with zero too, as a different object -- ok, error, message -- because the status answers a question the object cannot: whether an answer arrived at all. Only a flag the command does not have and a second filename fall outside this, and those end in prose on standard error.
A post sent from the phone itself
A phone writes through the blog.sh apps for iOS and Android. They reach the engine over the SSH the server already has, through one forced command (Over SSH, from an app): ./blog.sh pair lets an app in by a code, and a new post travels as a delivery -- the pictures, then the markdown, down one connection -- which scripts/remote.sh hands to scripts/receive.sh, the receiver this section describes.
The apps are the way a phone writes: since 1.11 the engine has no web page for it and no iOS shortcut. A site that still says write: true in site.yml hears about it from doctor -- nothing reads the key any more, and the line can go. The receiver is the same as it was, and so is the receipt: line of a delivery, which is what makes a delivery that arrives twice one post.
Publishing and the drafts, through the receiver. A delivery of exactly one file called publish.txt, holding the slug of a draft, is not stored: the receiver runs publish <slug> --yes --json and answers with that. One called drafts.txt, holding all or the slug of a draft, is answered with drafts --json -- with a slug, for that draft. The word is checked as hard as a filename is, because it becomes an argument to a command: a leading dash is a flag, and anything outside a slug's own alphabet is refused here rather than explained by whatever it hits. The apps ask through remote.sh instead; these two are for anything that has the receiver and nothing else.
A file named <name>.md.txt is taken as <name>.md. Chromium shares from a page only a file whose extension is on its own list, and .txt is on it while .md is not; the receiver puts the .md back before it checks the names, so a.md beside a.md.txt is one name twice.
Editing a draft from the phone
This is what an app does: it asks the blog for its drafts (drafts --json) and sends the text back with edits: <slug> and base: <digest> in its header -- see Over SSH, from an app, and the header keys for what such a save keeps and what it refuses.
A delivery that arrives twice is one post. The receipt is minted once per send, immediately before the files it names are built, so two deliveries carrying the same one are the same send arriving twice -- which is what a connection that breaks after the bytes have gone but before the answer comes back produces, and the apps retry. The second delivery updates the post the first one wrote instead of founding another beside it -- and that holds when the retry arrives while the first is still being written, because writes carrying a receipt take turns. Once the post is published, a late retry stops updating anything at all: it is answered with the published post, at its public address, and the file is left exactly as it stands. The copy the phone is still holding was made before publishing happened and cannot know about it, so letting it write would put the post back to draft -- with a new address, a new date and the announcement pointing at nothing. Pressing send again is not that: the app mints a fresh receipt each time, so a second send is a second post. A delivery carrying no receipt at all -- anything hand-rolled -- has nothing to be recognised by, and a repeat of one is two posts as it always was.
One connection carries the post however many photographs are in it, which is the point: connections are the scarce thing, not bytes.
The order inside the batch matters, because the markdown arriving is what makes the post and everything its text names has to be on the server by then. The app puts the markdown last for exactly this reason. Get it wrong and nothing breaks -- the engine answers missing_images and writes nothing, and sending the text again once the pictures are up is all it takes.
Draft or public is decided when the post is sent. A post is a draft unless its front matter says publish: yes, and then add takes the road publish <slug> --yes takes at a desk: the date is settled, the announcement goes out to the networks the site has configured, the site is rebuilt and deployed, and the answer carries the public address rather than a draft one. There is no third state: a post that is public is announced, on a phone as at a desk. The key is only read by add <file>; the wizard never publishes directly.
add <file> wants the file to be on the server already. receive.sh is how it gets there: the whole post down one connection. Each file is a name on its own line, its base64 after it, and a line holding a single . to say that was all of it -- then the next name.
{ for f in photo.jpg post.md; do
printf '%s\n' "$f"; base64 < "$f"; printf '.\n'
done
} | ssh blog ./scripts/receive.sh
One connection, not one per file. It was one per file once, which is simpler and does not work: a server worth running drops new SSH connections that arrive in a rush, and a common setting allows about four a minute. A post with three photographs sat exactly on that line and one with nine had no chance -- the sender saw "could not connect to the SSH server" and the pictures that never arrived were missed by nobody, since each connection answered for itself alone.
Every name in the delivery is read before a single byte is written, so a batch refused on its fifth name leaves nothing behind from the first four.
The closing dot is not decoration. A connection that drops halfway ends the same way a finished one does -- the receiver reads to the end of the stream either way -- so half a photograph arrived, decoded into half a picture, and was answered with ok. Without the dot the transfer is refused as truncated and nothing is stored.
An app sends a whole post that way -- every picture, then the markdown, down one connection -- and the markdown last, because the markdown arriving is what makes the post. Everything its text names is already staged under the name it uses, so there is no other signal to send and none is needed. The answer to a picture is {"ok":true,"stored":"photo.jpg"}; the answer to the markdown is the same JSON add --json gives.
⚠️ A sender has to read the answer, or every refusal looks like it worked. A refusal leaves with zero -- deliberately, because a phone discards the output of a remote command that failed (iOS Shortcuts did, which is how this was learned), and the reason is the whole point of the answer. The cost is that the status alone reports a refusal exactly as it reports a post. The reply is one JSON object per file, so read it whole: a picture answers "ok":true and the name it was stored under, a refusal answers "ok":false and names the reason, and the post that was written answers with its slug (and, since 1.10, "ok":true like every other answer).
The exit code answers a different question from the JSON. Zero means an answer arrived -- read the object, which says "ok" and, when that is false, names the reason. Non-zero means there is no object to read at all: the script was killed, or the shell never got to run it. Everything the receiver can put into words leaves with zero, and that includes the refusals about the installation rather than the delivery -- no incoming/, no engine, a ceiling that is not a number. Which kind of trouble it is, the error code says. (iOS Shortcuts discards the output of a remote command that failed, so a refusal that exited non-zero reached a phone as a bare status with its reason gone -- exactly when the reason was the point, and those refusals are the ones a new install meets on its very first delivery.)
The body has a deadline of its own, BLOGSH_BODY_SECONDS (600): a delivery that has not finished by then is dropped and, if the sender is still listening, told timeout; it is set where BLOGSH_MAX_MB is, below. Two files under one name in one delivery are refused (bad_name) rather than one silently replacing the other, every body is decoded before any file is written, so a refusal on the third picture leaves nothing of the first two behind, and a blank line after a complete delivery is not held against it. When the engine itself does not answer in JSON -- no env.sh, no ruby, a configuration that will not parse -- the receiver answers for it with engine_failed and the words the engine printed, and every delivery ends with status 0 once an answer has been given -- a ceiling that is not a number (bad_limit) included.
Deliveries are taken in one at a time. From the first file of a delivery landing in incoming/ to the engine having taken them out again, a second delivery waits: incoming/ is one folder, a picture is known there by the name it was sent under, and two phones -- or one app sending two posts -- both call their first picture 01.jpg. The one that waits does so for up to BLOGSH_TURN_SECONDS (300, set where the other two are) and is then told busy, with nothing of it stored; send it again. A delivery that died mid-way does not hold the next one up.
A delivery that goes wrong halfway can simply be repeated. Pictures wait in incoming/ until a text names them, so a refused post leaves them where they are and sending it again finds them -- nothing has to be uploaded twice.
Nothing new listens on the network. It travels over the SSH the server already has, and the key it travels on wants a forced command:
restrict,command="/path/to/blog/scripts/receive.sh" ssh-ed25519 AAAA... phone
What a stranger chooses is a filename and some bytes, so that is what is checked. A name carrying a path or a backslash, beginning with a dot, empty, longer than a filesystem will take, or holding a control character is refused (bad_name) and nothing is written. What arrives is bounded before it lands rather than weighed afterwards: BLOGSH_MAX_MB (24) is a ceiling on reading, so a sender costs that much and not whatever they felt like sending. The number is measured on the encoded stream, not on the files -- base64 is a third larger -- so a 24 MB ceiling takes about eighteen megabytes of photographs, and the apps measure a delivery the same way before they send it. A delivery that overshoots is read to its end into nothing -- up to four times the ceiling -- and then refused, so the sender finishes and hears too_large; refused the moment the ceiling was reached, a phone with megabytes still to send sat on "running" with no timeout to save it, and the answer never arrived. Beyond that bound the channel closes, and a hostile sender costs reading, never storage. And the post itself is handed to the engine as untrusted, so a picture may be named only by a bare filename --  is refused (bad_reference), because otherwise it would read that file into the post and publish it.
Raising the ceiling is one setting, in the right place. The receiver reads BLOGSH_MAX_MB from its own environment -- the one the forced command runs in: put it in the key's line, command="BLOGSH_MAX_MB=64 /path/to/blog/scripts/receive.sh", or, where the command is a wrapper that enters a container, in that wrapper (docker exec -e BLOGSH_MAX_MB=64 …). An app learns the number from version --json, which runs through the same door in the same environment, so the two agree.
There is deliberately no archive. An earlier design took a ZIP and unpacked it here; three adversarial audits found blocking faults in three successive rewrites of it, and nearly all of them lived in the unpacking -- entries that were symlinks, names that collapsed onto each other, a bomb that wrote gigabytes from megabytes, a half-failed extraction that published a truncated photograph and reported success. None of that can be expressed when there is nothing to unpack.
