feat(microblog): set and create categories

A piece's `category:` frontmatter line now travels to Micro.blog: a
first send carries the list beside title and content, and a re-send
replaces the post's categories with exactly the piece's list — only
when the piece has the line (opt-in by key; `[]` clears; no line
leaves the blog's). Naming a category Micro.blog doesn't know creates
it there, so there is no separate create step.

The publish sheet gains a Categories field: a comma list with the
system completion menu over the blog's own categories. The system
replaces the whole field text with a completion, so the completion is
the merge — a pick adds, a half-typed last word is replaced. The edit
lands on the piece at the send (a failed write refuses with nothing
on the wire); Publish with a pending edit applies it first and flips
the post that send touched.

The one-line codec lives in PostFrontmatter (line-bounded; backslashes
and quotes escaped; a Set de-duplicates). Import keeps an imported
`category:` line — the writer's classification, unlike the micropub
bookkeeping keys.

Reviewed twice (two-axis during the build, finish-audit after): the
stale pending baseline after a failed step, the backslash round-trip,
and the publish targeting the caller's possibly-stale URL were found
and fixed before this commit. 39 of the 40 new or changed pins were
watched fail on their own guard. Rail 791/791; SwiftFormat and
SwiftLint clean.

Docs: AGENTS.md bullets and learnings, the GLOSSARY term, CHANGELOG
[Unreleased], PRD S6.1, the devlog, and the swift wiki (text
completion is a whole-text contract).

Closes #207
This commit is contained in:
AlexKucera committed 2026-12-05 08:09:57 +01:00
1 parent 6aa31a419a
commit 6db4cf8cf1
18 files changed
+1629 -67

No files matched your search

+16 -2
View File
@@ -10,8 +10,9 @@
// confirms publish
// Then Micro.blog receives an h=entry create (markdown content, name,
// post-status=draft) followed by an update flipping post-status to
// published — the piece's frontmatter `category:` never travels, and
// the draft URL is remembered on the piece.
// published; #207: the piece's `category:` list rides the create (its
// own pins: MicropubCategoryTests) — and the draft URL is remembered
// on the piece.
//
// Wire facts live-verified against microblog.dev/api/posting and
// Micro.blog's Micropub docs (2026-10-31): JSON create reads
@@ -85,6 +86,19 @@ nonisolated func micropubJSON(_ request: URLRequest) -> [String: Any] {
return (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] ?? [:]
}
/// A saved `# Titled` piece carrying `frontmatter` planted after the
/// owned keys (a `category:` or `micropub_url:` line) — its id. The
/// anchor is `origin: writer`, the last key `writeNew` stamps.
nonisolated func plantedPiece(_ home: URL, frontmatter: String = "") throws -> String {
let post = try PostStore.writeNew(body: "# Titled\n\nBody.", home: home)
guard !frontmatter.isEmpty else { return post.id }
let fileURL = try #require(PostStore.folder(of: post.id, home: home)?.appendingPathComponent("post.md"))
try String(contentsOf: fileURL, encoding: .utf8)
.replacingOccurrences(of: "origin: writer\n", with: "origin: writer\n" + frontmatter)
.write(to: fileURL, atomically: true, encoding: .utf8)
return post.id
}
@Suite("MicropubTests")
struct MicropubTests {
// MARK: Request shapes (the wire contract)