feat(library): projects & archive substrate — S1 (#107)
CI / ci (push) Canceled after 0s

Pieces re-root from posts/<id>/ to projects/<name>/<id>/ with an
archive/ twin root (ADR-0012): scan walks both levels, New Piece and
Import land in the selected project else the default posts, the slug
namespace is global across projects and archive (an archived slug is
never reused), and every piece carries type: post frontmatter —
stamped by New/Import, read leniently (absent or unknown reads as
post), the file stays post.md for every content type. Write paths
resolve the folder from the id alone (folder(of:)); sessions and
sidecars never thread (project, id).

Finish-audit hardening: duplicate ids on disk (Finder copy) dedupe in
scan to the same first-match folder(of:) writes to; folder(of:) skips
hidden/symlinked projects like scan does.

Dev posts moved by hand to projects/posts/ — no migration machinery,
the app never reads the old posts/ root (#103). Full suite green
(128 unit + UI), swiftlint clean on changed files.

Closes #107
This commit is contained in:
AlexKucera committed 2026-10-13 17:44:44 +02:00
1 parent 50eecc6dcb
commit 3ca9d4e601
17 files changed
+608 -197

No files matched your search

+18 -13
View File
@@ -52,18 +52,12 @@ final class EditorSession {
return nil
}
/// The document's folder — `posts/<id>/` for posts (image resolution
/// #71); the external file's containing folder, so relative images
/// resolve beside the file.
var folderURL: URL {
switch target {
case let .post(id, home):
home.appendingPathComponent("posts", isDirectory: true)
.appendingPathComponent(id, isDirectory: true)
case let .externalFile(url):
url.deletingLastPathComponent()
}
}
/// The document's folder — the piece's resolved folder under projects/
/// or archive/ for posts (image resolution #71; resolved once at init,
/// ADR-0012 — a vanished piece still needs some path, so an unresolvable
/// id falls back to the default-project path); the external file's
/// containing folder, so relative images resolve beside the file.
private(set) var folderURL: URL
/// Current body text (live, per keystroke).
private(set) var text: String
@@ -101,6 +95,15 @@ final class EditorSession {
init(target: SessionTarget, debounce: Duration = .seconds(1)) {
self.target = target
self.debounce = debounce
switch target {
case let .post(id, home):
folderURL = PostStore.folder(of: id, home: home)
?? home.appendingPathComponent("projects", isDirectory: true)
.appendingPathComponent(Post.defaultProject, isDirectory: true)
.appendingPathComponent(id, isDirectory: true)
case let .externalFile(url):
folderURL = url.deletingLastPathComponent()
}
let read = Self.readDocument(target)
loadFailed = read == nil
let body = read ?? ""
@@ -128,7 +131,9 @@ final class EditorSession {
return PostStore.readBody(id: id, home: home)
case let .externalFile(url):
guard var text = try? String(contentsOf: url, encoding: .utf8) else { return nil }
if text.hasPrefix("\u{FEFF}") { text.removeFirst() }
if text.hasPrefix("\u{FEFF}") {
text.removeFirst()
}
return text.replacingOccurrences(of: "\r\n", with: "\n")
}
}