import Foundation struct DenoteNote: Identifiable, Hashable { let id: String let filename: String let path: String let title: String let keywords: [String] let fileExtension: String let modifiedDate: Date? var content: String? var displayTitle: String { title.isEmpty ? filename : title } var formattedDate: String { guard let date = modifiedDate else { return "" } let f = DateFormatter() f.dateStyle = .medium f.timeStyle = .none return f.string(from: date) } // Parses a Denote filename from a WebDAV href. // Expected format: /notes/YYYYMMDDTHHMMSS(==SIGNATURE)?(--TITLE)?(__KW1_KW2)?.EXT static func parse(href: String, modifiedDate: Date?) -> DenoteNote? { let filename = href.split(separator: "/").last.map(String.init) ?? href guard filename.range(of: #"^\d{8}T\d{6}"#, options: .regularExpression) != nil else { return nil } guard !filename.hasSuffix(".organice-bak"), !filename.hasSuffix(".bak"), filename != "DavLock" else { return nil } let nameWithoutExt: String let ext: String if let dotIndex = filename.lastIndex(of: ".") { nameWithoutExt = String(filename[.. String { slug.replacingOccurrences(of: "-", with: " ") .split(separator: " ") .map { $0.prefix(1).uppercased() + $0.dropFirst() } .joined(separator: " ") } func hash(into hasher: inout Hasher) { hasher.combine(id) } static func == (lhs: DenoteNote, rhs: DenoteNote) -> Bool { lhs.id == rhs.id } }