Commit 6be12de78e

6be12de78edd90e1ce2af15eceaece2bb15da855

parent: 1e56a2e00d

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-21 09:40 UTC

Publish on iOS without the device user as author

Layout: unified · split

Sources/OrgApp/Publish.swift +6 −5
@@ -252,9 +252,10 @@ public enum Publish {
252 252
253 /// `org-publish-projects`: each project's sitemap, when it has one, then its files, through 253 /// `org-publish-projects`: each project's sitemap, when it has one, then its files, through
254 /// its publishing functions. A file whose output is newer than it is skipped unless `force`. 254 /// its publishing functions. A file whose output is newer than it is skipped unless `force`.
255 /// `export` turns an Org file's text into the HTML, Markdown, LaTeX or plain text to write. 255 /// `export` turns an Org file's text into the HTML, Markdown, LaTeX or plain text to write;
256 /// ODT is exported here, with `author` for a file without `#+AUTHOR:`.
256 public static func publish( 257 public static func publish(
257 _ chosen: [PublishProject], all: [PublishProject], force: Bool = false, only: String? = nil, 258 _ chosen: [PublishProject], all: [PublishProject], force: Bool = false, only: String? = nil, author: String = NSFullUserName(),
258 read: (String) -> String?, export: (_ function: String, _ text: String, _ path: String, _ bodyOnly: Bool) throws -> String 259 read: (String) -> String?, export: (_ function: String, _ text: String, _ path: String, _ bodyOnly: Bool) throws -> String
259 ) throws -> Report { 260 ) throws -> Report {
260 var report = Report() 261 var report = Report()
@@ -276,7 +277,7 @@ public enum Publish {
276 continue 277 continue
277 } 278 }
278 try fm.createDirectory(atPath: (output as NSString).deletingLastPathComponent, withIntermediateDirectories: true) 279 try fm.createDirectory(atPath: (output as NSString).deletingLastPathComponent, withIntermediateDirectories: true)
279 try write(file, to: output, function: function, bodyOnly: p.bodyOnly, read: read, export: export) 280 try write(file, to: output, function: function, bodyOnly: p.bodyOnly, author: author, read: read, export: export)
280 report.published.append(file) 281 report.published.append(file)
281 } 282 }
282 } 283 }
@@ -328,7 +329,7 @@ public enum Publish {
328 /// Copies an attachment to `output`, or writes what `function` exports from `file`; ODT is 329 /// Copies an attachment to `output`, or writes what `function` exports from `file`; ODT is
329 /// exported here, with the preferences' settings. 330 /// exported here, with the preferences' settings.
330 private static func write( 331 private static func write(
331 _ file: String, to output: String, function: String, bodyOnly: Bool, 332 _ file: String, to output: String, function: String, bodyOnly: Bool, author: String,
332 read: (String) -> String?, export: (_ function: String, _ text: String, _ path: String, _ bodyOnly: Bool) throws -> String 333 read: (String) -> String?, export: (_ function: String, _ text: String, _ path: String, _ bodyOnly: Bool) throws -> String
333 ) throws { 334 ) throws {
334 let fm = FileManager.default 335 let fm = FileManager.default
@@ -338,7 +339,7 @@ public enum Publish {
338 } else if function == "org-odt-publish-to-odt" { 339 } else if function == "org-odt-publish-to-odt" {
339 let text = read(file) ?? "" 340 let text = read(file) ?? ""
340 let settings = OrgPreferences.orgSettings().resolvingSetupFiles(in: text, path: file, read: OrgSettings.readFile) 341 let settings = OrgPreferences.orgSettings().resolvingSetupFiles(in: text, path: file, read: OrgSettings.readFile)
341 try ODTExport.document(text, settings: settings, path: file, author: NSFullUserName(), language: OrgPreferences.exportLanguage()) 342 try ODTExport.document(text, settings: settings, path: file, author: author, language: OrgPreferences.exportLanguage())
342 .write(to: URL(fileURLWithPath: output), options: .atomic) 343 .write(to: URL(fileURLWithPath: output), options: .atomic)
343 } else { 344 } else {
344 try export(function, read(file) ?? "", file, bodyOnly).write(toFile: output, atomically: true, encoding: .utf8) 345 try export(function, read(file) ?? "", file, bodyOnly).write(toFile: output, atomically: true, encoding: .utf8)
Sources/OrgstarMobile/EditorScreen.swift +3 −2
@@ -686,8 +686,9 @@ extension EditorScreen {
686 session.openDocuments.first { $0.path == file }?.document.text ?? (try? String(contentsOfFile: file, encoding: .utf8)) 686 session.openDocuments.first { $0.path == file }?.document.text ?? (try? String(contentsOfFile: file, encoding: .utf8))
687 } 687 }
688 let codeStyle = HTMLCodeStyle(highlighter: MobileEditor.highlighter, theme: model.theme) 688 let codeStyle = HTMLCodeStyle(highlighter: MobileEditor.highlighter, theme: model.theme)
689 let report = try Publish.publish(chosen, all: all, only: only, read: read) { function, text, file, bodyOnly in 689 // As the Export menu: no author unless the file has #+AUTHOR:.
690 try Publish.export(function, text: text, path: file, bodyOnly: bodyOnly, settings: OrgPreferences.orgSettings(), codeStyle: codeStyle) 690 let report = try Publish.publish(chosen, all: all, only: only, author: "", read: read) { function, text, file, bodyOnly in
691 try Publish.export(function, text: text, path: file, bodyOnly: bodyOnly, settings: OrgPreferences.orgSettings(), codeStyle: codeStyle, author: "")
691 } 692 }
692 message = "Published \(report.published.count) files" + (report.skipped.isEmpty ? "" : ", \(report.skipped.count) up to date") 693 message = "Published \(report.published.count) files" + (report.skipped.isEmpty ? "" : ", \(report.skipped.count) up to date")
693 } catch { 694 } catch {
Tests/OrgAppTests/PublishTests.swift +15
@@ -261,6 +261,21 @@ struct PublishTests {
261 #expect(String(decoding: data[30..<38], as: UTF8.self) == "mimetype") 261 #expect(String(decoding: data[30..<38], as: UTF8.self) == "mimetype")
262 } 262 }
263 263
264 /// The ODT author comes from the caller: iOS passes none, as its Export menu does.
265 @Test func publishesODTWithTheCallersAuthor() throws {
266 let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-publish-\(UUID().uuidString)")
267 defer { try? FileManager.default.removeItem(at: folder) }
268 try Self.tree(folder)
269 let config = "[[publish]]\nname = \"odt\"\nbase-directory = \"\(folder.path)/src\"\npublishing-directory = \"\(folder.path)/odt\"\npublishing-function = \"org-odt-publish-to-odt\"\n"
270 let loaded = Publish.projects(fromConfig: config, root: nil)
271 let read = { (path: String) in try? String(contentsOfFile: path, encoding: .utf8) }
272 let odt = folder.appendingPathComponent("odt/a.odt")
273 _ = try Publish.publish(loaded.projects, all: loaded.projects, author: "Quill Writer", read: read) { _, _, _, _ in "" }
274 #expect(try Data(contentsOf: odt).range(of: Data("Quill Writer".utf8)) != nil)
275 _ = try Publish.publish(loaded.projects, all: loaded.projects, force: true, author: "", read: read) { _, _, _, _ in "" }
276 #expect(try Data(contentsOf: odt).range(of: Data("Quill Writer".utf8)) == nil)
277 }
278
264 @Test func skipsUpToDateFilesAndFindsProjects() throws { 279 @Test func skipsUpToDateFilesAndFindsProjects() throws {
265 let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-publish-\(UUID().uuidString)").resolvingSymlinksInPath() 280 let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-publish-\(UUID().uuidString)").resolvingSymlinksInPath()
266 defer { try? FileManager.default.removeItem(at: folder) } 281 defer { try? FileManager.default.removeItem(at: folder) }
docs/manual/guide/12-export.org +1 −1
@@ -364,7 +364,7 @@ components = "notes static"
364 364
365Files whose names start with a dot are left out. An Org file publishes to the same path under =publishing-directory=, named by =#+EXPORT_FILE_NAME= when it has one, with links to other =.org= files pointing to their =.html=. The sitemap lists each file as a link with its =#+TITLE= (or its name), as Org's default sitemap does. 365Files whose names start with a dot are left out. An Org file publishes to the same path under =publishing-directory=, named by =#+EXPORT_FILE_NAME= when it has one, with links to other =.org= files pointing to their =.html=. The sitemap lists each file as a link with its =#+TITLE= (or its name), as Org's default sitemap does.
366 366
367On the Mac, File ▸ Publish has the commands, which are also in the command palette. On iOS they are in Commands in the editor; Publish Project… lists the projects to choose from. 367On the Mac, File ▸ Publish has the commands, which are also in the command palette. On iOS they are in Commands in the editor; Publish Project… lists the projects to choose from. As with the iOS share sheet, LaTeX, ODT and plain text published on iOS have no author unless the file has =#+AUTHOR:=.
368 368
369| Command | Emacs preset | What it does | 369| Command | Emacs preset | What it does |
370|-------------------------+---------------+------------------------------------------------------------| 370|-------------------------+---------------+------------------------------------------------------------|