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
+38
-22
@@ -28,10 +28,18 @@ nonisolated struct Post: Identifiable, Equatable {
|
||||
var project: String
|
||||
/// True when the piece lives under archive/ (#107).
|
||||
var isArchived: Bool
|
||||
/// #33 (S6.1): the remembered Micro.blog draft URL (frontmatter
|
||||
/// `micropub_url`) — set when a draft was sent, the target the
|
||||
/// publish step updates. Inert to everything else.
|
||||
/// #33 (S6.1): the remembered Micro.blog post URL (frontmatter
|
||||
/// `micropub_url`) — set when a draft was sent; the target the
|
||||
/// publish step updates and a re-send replaces in place (#206), and
|
||||
/// half of the row's status. Inert to everything else.
|
||||
var micropubURL: String?
|
||||
/// #206: when Publish succeeded — frontmatter `micropub_published`,
|
||||
/// the `stats_captured` stamp shape (local time). The Museion-side
|
||||
/// publish record: the library answers "is this piece out, and
|
||||
/// since when" from disk, never from a live query. Nil = never
|
||||
/// published from here (a piece published before this stamp read
|
||||
/// as a draft until its next Publish).
|
||||
var micropubPublished: Date?
|
||||
/// #32 (S5.2): the captured first-draft stats — present ONLY when
|
||||
/// `captureFirstDraftStats` stamped the piece at a pass invocation
|
||||
/// (writer origin, First Draft, post type, decided there against the
|
||||
@@ -41,6 +49,15 @@ nonisolated struct Post: Identifiable, Equatable {
|
||||
/// keys, and non-writer or outline pieces never render them.
|
||||
var firstDraftStats: FirstDraftStats?
|
||||
|
||||
/// #206: the row's Micro.blog status — nil when the piece was never
|
||||
/// sent; a remembered URL alone is a draft; the publish stamp wins.
|
||||
var micropubStatus: String? {
|
||||
if let micropubPublished {
|
||||
return "published \(Micropub.shortDate(micropubPublished))"
|
||||
}
|
||||
return micropubURL == nil ? nil : "draft on Micro.blog"
|
||||
}
|
||||
|
||||
/// New pieces land here when no project is selected (#107).
|
||||
static let defaultProject = "posts"
|
||||
|
||||
@@ -58,7 +75,7 @@ nonisolated struct Post: Identifiable, Equatable {
|
||||
/// reads "steady" in the verdict (finish-audit #32).
|
||||
init?(frontmatter: [String: String]) {
|
||||
guard
|
||||
let captured = frontmatter["stats_captured"].flatMap(Self.parseCaptured),
|
||||
let captured = frontmatter["stats_captured"].flatMap(Post.parseStamp),
|
||||
let burstiness = frontmatter["stats_burstiness"].flatMap(Self.finite),
|
||||
let typeTokenRatio = frontmatter["stats_type_token_ratio"].flatMap(Self.finite),
|
||||
let sentenceVariation = frontmatter["stats_sentence_variation"].flatMap(Self.finite),
|
||||
@@ -73,15 +90,6 @@ nonisolated struct Post: Identifiable, Equatable {
|
||||
)
|
||||
}
|
||||
|
||||
/// The symmetric read of the capture stamp (`FixCardStore.formatted`,
|
||||
/// local time) — per-access formatter, the repo's no-static convention.
|
||||
private static func parseCaptured(_ stamp: String) -> Date? {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
return formatter.date(from: stamp)
|
||||
}
|
||||
|
||||
/// Frontmatter is external data (hand-edits, imports): reject the
|
||||
/// non-finite doubles Swift's `Double(String)` happily parses.
|
||||
private static func finite(_ raw: String) -> Double? {
|
||||
@@ -189,15 +197,12 @@ nonisolated struct Post: Identifiable, Equatable {
|
||||
type: stamp.type,
|
||||
project: project,
|
||||
isArchived: isArchived,
|
||||
// #33: the remembered Micro.blog draft URL —
|
||||
// one flat key, read leniently like the rest.
|
||||
// #33 audit: imported frontmatter rides
|
||||
// verbatim, so the read-back gates on the same
|
||||
// format guard the decode applies — a hostile
|
||||
// value never pre-arms the publish sheet.
|
||||
micropubURL: frontmatter["micropub_url"].flatMap {
|
||||
Micropub.trustworthyURL($0) ? $0 : nil
|
||||
},
|
||||
// #33: the remembered Micro.blog URL — one flat key
|
||||
// through the ONE trust gate (an import drops the key,
|
||||
// #206, so a hostile value never pre-arms the publish
|
||||
// sheet); #206: the publish stamp beside it.
|
||||
micropubURL: Micropub.rememberedURL(frontmatter),
|
||||
micropubPublished: frontmatter["micropub_published"].flatMap(parseStamp),
|
||||
// #32/#180 read-back gate: the named immutable pair
|
||||
// (origin writer, type post) — NOT pass_state, which
|
||||
// legitimately advances after the capture. `stats_*`
|
||||
@@ -210,6 +215,17 @@ nonisolated struct Post: Identifiable, Equatable {
|
||||
)
|
||||
}
|
||||
|
||||
/// The frontmatter timestamp reader — `yyyy-MM-dd'T'HH:mm:ss`, local
|
||||
/// time (`FixCardStore.formatted`'s writer side); nil on anything
|
||||
/// else. The symmetric read of the #31 capture stamp and the #206
|
||||
/// publish stamp. Per-access formatter, the repo's no-static convention.
|
||||
private static func parseStamp(_ stamp: String) -> Date? {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = PostFrontmatter.stampFormat
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
return formatter.date(from: stamp)
|
||||
}
|
||||
|
||||
/// The Post's Title: first non-empty line after any frontmatter block,
|
||||
/// `#` heading markers stripped; `untitled` when nothing readable remains.
|
||||
static func title(of text: String) -> String {
|
||||
|
||||
Reference in new issue
Block a user