From cdaaa363035a8b3707ffaa3a7a0c405ad5fba98a Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sat, 14 Dec 2024 18:26:11 +0100 Subject: [PATCH] Fix icons, external file rename --- CHDataManagement.xcodeproj/project.pbxproj | 4 --- .../Page Content/LabelsCommand.swift | 1 + .../Generator/PageCommandExtractor.swift | 32 ------------------- CHDataManagement/Main/MainView.swift | 5 +-- CHDataManagement/Model/FileResource.swift | 17 ++++++++++ .../Views/Files/FileDetailView.swift | 7 +--- 6 files changed, 22 insertions(+), 44 deletions(-) delete mode 100644 CHDataManagement/Generator/PageCommandExtractor.swift diff --git a/CHDataManagement.xcodeproj/project.pbxproj b/CHDataManagement.xcodeproj/project.pbxproj index db3ab0f..2f10eb5 100644 --- a/CHDataManagement.xcodeproj/project.pbxproj +++ b/CHDataManagement.xcodeproj/project.pbxproj @@ -114,7 +114,6 @@ E29D318B2D0B07EE0051B7F4 /* ContentBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29D318A2D0B07E60051B7F4 /* ContentBox.swift */; }; E29D318E2D0B2E680051B7F4 /* PageSettingsContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29D318D2D0B2E640051B7F4 /* PageSettingsContentView.swift */; }; E29D31902D0B34870051B7F4 /* PageContentAnomaly.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29D318F2D0B34870051B7F4 /* PageContentAnomaly.swift */; }; - E29D31922D0B3EFC0051B7F4 /* PageCommandExtractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29D31912D0B3EF30051B7F4 /* PageCommandExtractor.swift */; }; E29D31942D0B7D280051B7F4 /* SvgImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29D31932D0B7D250051B7F4 /* SvgImage.swift */; }; E29D31962D0C186E0051B7F4 /* PathSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29D31952D0C18690051B7F4 /* PathSettings.swift */; }; E29D31982D0C19340051B7F4 /* PathSettingsFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29D31972D0C19300051B7F4 /* PathSettingsFile.swift */; }; @@ -282,7 +281,6 @@ E29D318A2D0B07E60051B7F4 /* ContentBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentBox.swift; sourceTree = ""; }; E29D318D2D0B2E640051B7F4 /* PageSettingsContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageSettingsContentView.swift; sourceTree = ""; }; E29D318F2D0B34870051B7F4 /* PageContentAnomaly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageContentAnomaly.swift; sourceTree = ""; }; - E29D31912D0B3EF30051B7F4 /* PageCommandExtractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageCommandExtractor.swift; sourceTree = ""; }; E29D31932D0B7D250051B7F4 /* SvgImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SvgImage.swift; sourceTree = ""; }; E29D31952D0C18690051B7F4 /* PathSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathSettings.swift; sourceTree = ""; }; E29D31972D0C19300051B7F4 /* PathSettingsFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathSettingsFile.swift; sourceTree = ""; }; @@ -405,7 +403,6 @@ isa = PBXGroup; children = ( E29D31B62D0DAC030051B7F4 /* Page Content */, - E29D31912D0B3EF30051B7F4 /* PageCommandExtractor.swift */, E29D318F2D0B34870051B7F4 /* PageContentAnomaly.swift */, E29D31842D0AE8EE0051B7F4 /* RequiredHeaders.swift */, E25DA5222CFF6C2600AEF16D /* ImageGenerator.swift */, @@ -891,7 +888,6 @@ E2A21C2A2CB2AA4F0060935B /* Post+Mock.swift in Sources */, E29D312E2D03A0D70051B7F4 /* LocalizedPageDetailView.swift in Sources */, E2581DED2C75202400F1F079 /* Tag.swift in Sources */, - E29D31922D0B3EFC0051B7F4 /* PageCommandExtractor.swift in Sources */, E29D315B2D06D63E0051B7F4 /* ModelFileType.swift in Sources */, E29D31302D03A2C50051B7F4 /* DescriptionField.swift in Sources */, E29D31BE2D0DB85A0051B7F4 /* AudioPlayerCommand.swift in Sources */, diff --git a/CHDataManagement/Generator/Page Content/LabelsCommand.swift b/CHDataManagement/Generator/Page Content/LabelsCommand.swift index 71ae0ca..5502d20 100644 --- a/CHDataManagement/Generator/Page Content/LabelsCommand.swift +++ b/CHDataManagement/Generator/Page Content/LabelsCommand.swift @@ -23,6 +23,7 @@ struct LabelsCommandProcessor: CommandProcessor { results.invalid(command: .labels, markdown) return nil } + results.requiredIcons.insert(icon) return .init(icon: icon, value: parts[1]) } return ContentLabels(labels: labels).content diff --git a/CHDataManagement/Generator/PageCommandExtractor.swift b/CHDataManagement/Generator/PageCommandExtractor.swift deleted file mode 100644 index 6509b1f..0000000 --- a/CHDataManagement/Generator/PageCommandExtractor.swift +++ /dev/null @@ -1,32 +0,0 @@ -import Ink - -#warning("Remove if unused") -final class PageCommandExtractor { - - private var occurrences: [(full: String, command: String, arguments: [String])] = [] - - func findOccurrences(of command: ShorthandMarkdownKey, in content: String) -> [(full: String, arguments: [String])] { - findOccurrences(of: command.rawValue, in: content) - } - - func findOccurrences(of command: String, in content: String) -> [(full: String, arguments: [String])] { - let parser = MarkdownParser(modifiers: [ - Modifier(target: .images, closure: processMarkdownImage), - ]) - _ = parser.html(from: content) - - return occurrences - .filter { $0.command == command } - .map { ($0.full, $0.arguments) } - } - - private func processMarkdownImage(html: String, markdown: Substring) -> String { - let argumentList = markdown.between(first: "](", andLast: ")").removingPercentEncoding ?? markdown.between(first: "](", andLast: ")") - let arguments = argumentList.components(separatedBy: ";") - - - let command = markdown.between("![", and: "]").trimmed - occurrences.append((full: String(markdown), command: command, arguments: arguments)) - return "" - } -} diff --git a/CHDataManagement/Main/MainView.swift b/CHDataManagement/Main/MainView.swift index c3a175e..19dfd46 100644 --- a/CHDataManagement/Main/MainView.swift +++ b/CHDataManagement/Main/MainView.swift @@ -1,14 +1,15 @@ import SwiftUI import SFSafeSymbols +#warning("Fix podcast") #warning("Allow selection of pages as navigation bar items") +#warning("Add link to other language") #warning("Transfer images of posts to other language") #warning("Show tag selection view for pages") #warning("Button to replace files") -#warning("Add external pages") -#warning("Convert statistics into key-value pairs") #warning("Replace links to files inside pages when id changes") #warning("Calculate file sizes") +#warning("Specify image aspect ratio to prevent page jumps") @main struct MainView: App { diff --git a/CHDataManagement/Model/FileResource.swift b/CHDataManagement/Model/FileResource.swift index 26850c3..ce5d64d 100644 --- a/CHDataManagement/Model/FileResource.swift +++ b/CHDataManagement/Model/FileResource.swift @@ -116,6 +116,23 @@ final class FileResource: Item { default: return content.settings.paths.filesOutputFolderPath } } + + // MARK: File + + func update(id newId: String) -> Bool { + guard !isExternallyStored else { + id = newId + return true + } + do { + try content.storage.move(file: id, to: newId) + id = newId + return true + } catch { + print("Failed to move file \(id) to \(newId)") + return false + } + } } extension FileResource: Identifiable { diff --git a/CHDataManagement/Views/Files/FileDetailView.swift b/CHDataManagement/Views/Files/FileDetailView.swift index 23a4af4..ac81c89 100644 --- a/CHDataManagement/Views/Files/FileDetailView.swift +++ b/CHDataManagement/Views/Files/FileDetailView.swift @@ -55,14 +55,9 @@ struct FileDetailView: View { } private func setNewId() { - do { - try file.content.storage.move(file: file.id, to: newId) - } catch { - print("Failed to move file \(file.id)") + if !file.update(id: newId) { newId = file.id - return } - file.id = newId } }