feat(microblog): show Micro.blog publish status
The publish sheet flipped a draft live and remembered nothing, so nothing on disk said a piece was out and the library could not show it. A successful Publish now stamps `micropub_published` in the piece's frontmatter; the row and the sheet read `published <date>` or `draft on Micro.blog`, and a published piece's menu opens the live post. Sending a piece again no longer creates a second post: a piece that remembers its post updates it in place (name and content only, so categories set on Micro.blog survive). An image whose bytes are unchanged rides its earlier upload through a per-piece memo. When Micro.blog answers 404 the piece forgets both keys and the sheet offers a fresh draft; a clear that cannot land says so instead of claiming the link is gone. Museion's micropub keys are dropped at the import boundary. An imported `micropub_url` passes the format gate and would aim the in-place update at one of the writer's own posts under their token, so the keys are treated like `origin`: ours to set, never a foreign file's to carry in. Publish is model-owned and trust-gates its URL before anything is stamped. Tests read recorded requests through an optional accessor: an out-of-range subscript after a failed count expectation trapped the hosted runner and reported every queued test as crashed. +16 tests net (17 new pins in MicropubStatusTests, one retired whose premise the in-place design voids); every new pin was watched fail on its own guard. Rail 752/752; SwiftFormat and SwiftLint clean. Reviews: standards + spec during the build, then a three-reviewer finish audit. Docs: AGENTS.md bullets and learnings, GLOSSARY terms, CHANGELOG [Unreleased], README, and the devlog. Closes #206
This commit is contained in:
1 parent
6938826101
commit
6aa31a419a
21 files changed
+1151
-225
No files matched your search
@@ -24,7 +24,9 @@ import Foundation
|
||||
/// - **fresh** (`stamped`) — a brand-new block: writeNew, bare-file
|
||||
/// normalization on save/advance, convert. Replaces any existing block.
|
||||
/// - **merge-import** (`mergingImport`) — an external block kept verbatim
|
||||
/// with our three owned keys winning in place (importFile, #95).
|
||||
/// with our three owned keys winning in place (importFile, #95), and
|
||||
/// Museion's Micro.blog bookkeeping dropped (#206 — a foreign file
|
||||
/// carries no post of THIS library).
|
||||
/// - **update-keys** (`updating`) — the surgical in-place key stamp:
|
||||
/// every other line byte-identical (editor save, pass advance, stats
|
||||
/// capture, micropub URL, learnings dismiss).
|
||||
@@ -33,6 +35,19 @@ import Foundation
|
||||
/// `origin`) are ONE rule shared by every posture: absent owned keys
|
||||
/// insert before the closing `---` in that order.
|
||||
nonisolated enum PostFrontmatter {
|
||||
/// The frontmatter timestamp shape (`stats_captured`, #31;
|
||||
/// `micropub_published`, #206) — local time, lexically sortable. The
|
||||
/// one home for the format: both stamp writers and the reader share it.
|
||||
static let stampFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
||||
|
||||
/// Museion's Micro.blog bookkeeping — written only by the app (or the
|
||||
/// writer's own hand, the legacy migration), never trusted from
|
||||
/// outside: the import boundary DROPS these keys and the 404 forget
|
||||
/// removes them. #206: an imported `micropub_url` passes the format
|
||||
/// gate and would steer the next send's content replace — under the
|
||||
/// writer's token — onto whatever post it names.
|
||||
static let micropubKeys: Set<String> = ["micropub_url", "micropub_published"]
|
||||
|
||||
/// The leniently-decoded identity triple — one home for the `?? default`
|
||||
/// reads scan, the write paths, and the eligibility predicates share
|
||||
/// (the extraction the #31 capture's ponytail note deferred until this
|
||||
@@ -139,8 +154,9 @@ nonisolated enum PostFrontmatter {
|
||||
/// order), preserve every other line verbatim (leading hand-edit lines
|
||||
/// above the opening `---` included, #27 review), keep the block's
|
||||
/// trailing newline. No block at all → prepend a fresh one with the
|
||||
/// pairs.
|
||||
static func updating(text: String, with pairs: [(key: String, value: String)]) -> String {
|
||||
/// pairs. `dropping` removes those keys' lines outright, first (#206:
|
||||
/// the import boundary and the 404 forget).
|
||||
static func updating(text: String, with pairs: [(key: String, value: String)], dropping: Set<String> = []) -> String {
|
||||
let (block, body) = split(text)
|
||||
guard !block.isEmpty else {
|
||||
return "---\n" + pairs.map { "\($0.key): \($0.value)" }.joined(separator: "\n") + "\n---\n" + body
|
||||
@@ -159,17 +175,15 @@ nonisolated enum PostFrontmatter {
|
||||
// the lenient flat reader never claimed nested support (posture
|
||||
// inherited verbatim, #180 audit INFO-1). Indentation-aware walk
|
||||
// if nested frontmatter ever matters.
|
||||
if !dropping.isEmpty {
|
||||
lines.removeAll { key(ofLine: $0).map(dropping.contains) == true }
|
||||
}
|
||||
let oursByKey = Dictionary(pairs.map { ($0.key, $0.value) }, uniquingKeysWith: { first, _ in first })
|
||||
var seen = Set<String>()
|
||||
for (index, line) in lines.enumerated() {
|
||||
// whitespacesAndNewlines: CRLF lines carry a trailing \r.
|
||||
let trimmed = line.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty, trimmed != "---" else { continue }
|
||||
let key = String(line.split(separator: ":", maxSplits: 1).first ?? "").trimmingCharacters(in: .whitespaces)
|
||||
if let value = oursByKey[key] {
|
||||
lines[index] = "\(key): \(value)"
|
||||
seen.insert(key)
|
||||
}
|
||||
guard let key = key(ofLine: line), let value = oursByKey[key] else { continue }
|
||||
lines[index] = "\(key): \(value)"
|
||||
seen.insert(key)
|
||||
}
|
||||
let insertions = pairs.filter { !seen.contains($0.key) }.map { "\($0.key): \($0.value)" }
|
||||
if let close = lines.lastIndex(where: { $0.trimmingCharacters(in: .whitespacesAndNewlines) == "---" }), close > 0 {
|
||||
@@ -181,13 +195,30 @@ nonisolated enum PostFrontmatter {
|
||||
/// Posture 2 — merge-import: external frontmatter rides verbatim;
|
||||
/// `type: post`, `pass_state: First Draft`, `origin: <chosen>` win
|
||||
/// (#95: our three keys win — external `type: outline` still imports
|
||||
/// as post). The update posture over the known-key table.
|
||||
/// as post), and Museion's Micro.blog bookkeeping is dropped (#206: a
|
||||
/// foreign file carries no post of this library — its `micropub_url`
|
||||
/// would otherwise aim the next send's content replace). The update
|
||||
/// posture over the known-key table.
|
||||
///
|
||||
/// #180 divergence from the absorbed mergedFrontmatter, deliberate:
|
||||
/// hand-edit lines above the opening `---` now survive import (the old
|
||||
/// split-first shape silently dropped them) — lossless through every
|
||||
/// posture is the ticket's contract.
|
||||
static func mergingImport(text: String, origin: Post.Origin) -> String {
|
||||
updating(text: text, with: ownedKeys(type: .post, passState: .firstDraft, origin: origin))
|
||||
updating(
|
||||
text: text,
|
||||
with: ownedKeys(type: .post, passState: .firstDraft, origin: origin),
|
||||
dropping: micropubKeys,
|
||||
)
|
||||
}
|
||||
|
||||
/// A block line's key — the update posture's ONE key read (so the
|
||||
/// drop and the walk can never disagree about a line): leading and
|
||||
/// trailing whitespace trimmed, a trailing `\r` included (CRLF
|
||||
/// files). Nil for the fences and blank lines.
|
||||
private static func key(ofLine line: String) -> String? {
|
||||
let trimmed = line.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty, trimmed != "---" else { return nil }
|
||||
return String(line.split(separator: ":", maxSplits: 1).first ?? "").trimmingCharacters(in: .whitespaces)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user