feat(microblog): post summary for Micro.blog
A piece's `summary:` frontmatter line now travels to Micro.blog beside `category:`. A first send carries the summary when it is not empty; a re-send replaces the post's summary only when the piece has the line (opt-in by key; an empty value clears it; no line leaves the blog's). The same rule as categories, so a piece that never gained the line cannot blank a summary set on Micro.blog itself. The publish sheet gains a Summary field and an AI summary button. The button drafts a first-person teaser from the open piece on a fresh one-shot engine on the chat profile (the Blind Read's rail — the resident session is never touched); the reply fills the field for the writer to edit, and nothing is written until the send stamps the line. The sheet is modal, so while its own turn runs the button is the Stop; a Pass or Blind Read that owns the rail disables the button with the reason on hover and refuses from behind it. The summary is read off the RAW frontmatter line, never through the lenient decode — which trims every edge quote — and the read walks the block the way the lenient reader does. A `split`-based read finds no block in a mixed-ending file while the lenient reader still sees the key, and the empty value it answers would have been sent over a live post's summary. Reviewed twice (two-axis during the build, three-reviewer finish-audit after): the mixed-ending read, an unfenced body line claiming the key, the uncancellable modal turn, and the wrapper rule eating a teaser's edge quotes were found and fixed before this commit. Every guard was watched fail on its own pin. Rail 814/814; SwiftFormat and SwiftLint clean. Docs: AGENTS.md bullets and learnings, the GLOSSARY term, CHANGELOG [Unreleased], PRD S6.1, and the devlog. Closes #208
This commit is contained in:
1 parent
6db4cf8cf1
commit
36393a9e8e
22 files changed
+1096
-36
No files matched your search
@@ -247,6 +247,58 @@ nonisolated enum PostFrontmatter {
|
||||
"[" + categoryListValue(names) + "]"
|
||||
}
|
||||
|
||||
/// #208: the piece's summary from its raw frontmatter text — ONE
|
||||
/// line by construction (the read is line-bounded). Walks the block
|
||||
/// the way the lenient `parse` does (past the opening fence to the
|
||||
/// next `---`), but keeps the line's own quotes: `parse`'s scalar
|
||||
/// trim strips EVERY edge quote character, which would eat a
|
||||
/// teaser's closing `"why"`. A quoted value (the shape `summaryValue`
|
||||
/// renders) unescapes through the category codec's one unescape; a
|
||||
/// bare value is taken as written. No block, or no line → `""`, the
|
||||
/// field's settled empty: a piece without a line never gains one, and
|
||||
/// a BODY line named `summary:` never claims the key.
|
||||
static func summary(inText text: String) -> String {
|
||||
let lines = text.split(separator: "\n", omittingEmptySubsequences: false)
|
||||
for line in lines.drop(while: { $0.trimmed() != "---" }).dropFirst() {
|
||||
let trimmed = line.trimmed()
|
||||
guard trimmed != "---" else { break }
|
||||
guard trimmed.hasPrefix("summary:") else { continue }
|
||||
// A stray \r before the newline fuses the closing fence onto
|
||||
// this line (the last block line of a mixed-ending file) —
|
||||
// the fence is never part of the value.
|
||||
var raw = trimmed.dropFirst("summary:".count).trimmingCharacters(in: .whitespaces)
|
||||
if let fused = raw.range(of: "\r\n---") {
|
||||
raw = raw[..<fused.lowerBound].trimmingCharacters(in: .whitespaces)
|
||||
}
|
||||
if raw.hasPrefix("\""), raw.hasSuffix("\""), raw.count >= 2 {
|
||||
return categoryUnescaped(String(raw.dropFirst().dropLast()))
|
||||
}
|
||||
return raw
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
/// #208: the one-line `summary:` value `summary(inText:)` reads
|
||||
/// back. Control characters drop and every run of whitespace — a
|
||||
/// newline included — collapses to one space: the frontmatter sink
|
||||
/// is line-bounded, so the value is ONE line or nothing. A value
|
||||
/// holding a quote or backslash renders QUOTED with both escaped —
|
||||
/// the category codec's own escape, so ONE grammar serves both keys:
|
||||
/// the lenient `parse` trims every edge quote (a teaser's closing
|
||||
/// `"why"` would vanish through that door), so the summary is read
|
||||
/// off its raw line and the wire never ships an altered teaser.
|
||||
static func summaryValue(_ text: String) -> String {
|
||||
let flattened = text
|
||||
.split(whereSeparator: \.isWhitespace)
|
||||
.joined(separator: " ")
|
||||
.unicodeScalars.filter { !CharacterSet.controlCharacters.contains($0) }
|
||||
let cleaned = String(flattened)
|
||||
let needsQuoting = cleaned.contains(where: { "\"'\\".contains($0) })
|
||||
guard needsQuoting else { return cleaned }
|
||||
let slashed = cleaned.replacingOccurrences(of: "\\", with: "\\\\")
|
||||
return "\"" + slashed.replacingOccurrences(of: "\"", with: "\\\"") + "\""
|
||||
}
|
||||
|
||||
// MARK: - Write postures
|
||||
|
||||
/// The known-key table: Museion's three owned keys in stamp order —
|
||||
|
||||
Reference in new issue
Block a user