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

+6 -11
View File
@@ -88,15 +88,11 @@ struct MicropubModelTests {
#expect(Post.scan(home: home).first?.micropubURL == nil)
}
@Test @MainActor func `frontmatter category never travels`() async throws {
@Test @MainActor func `frontmatter category travels`() async throws {
let (model, home) = try makeModelHome()
let post = try PostStore.writeNew(body: "# Categorized\n\nBody.", home: home)
model.select(post.id)
// The writer's own category frontmatter — permitted, inert.
let fileURL = try #require(PostStore.folder(of: post.id, home: home)?.appendingPathComponent("post.md"))
let raw = try String(contentsOf: fileURL, encoding: .utf8)
try raw.replacingOccurrences(of: "origin: writer\n", with: "origin: writer\ncategory: Essays\n")
.write(to: fileURL, atomically: true, encoding: .utf8)
// The writer's own category frontmatter — #207: a bare scalar
// is ONE category, and it rides the create as `category`.
try model.select(plantedPiece(home, frontmatter: "category: Essays\n"))
let log = MicropubRequestLog()
_ = await model.micropubSend(
@@ -105,9 +101,8 @@ struct MicropubModelTests {
)
let request = try #require(log.requests.first)
let wire = String(bytes: request.httpBody ?? Data(), encoding: .utf8) ?? ""
#expect(!wire.lowercased().contains("category"))
#expect(!wire.contains("Essays"))
let props = try #require(micropubJSON(request)["properties"] as? [String: Any])
#expect(props["category"] as? [String] == ["Essays"])
}
@Test @MainActor func `a failed draft stamps nothing`() async throws {