ChWebsiteApp/CHDataManagement/Model/LocalizedPage.swift
2024-11-20 14:25:10 +01:00

101 lines
2.5 KiB
Swift

import Foundation
import SwiftUI
/**
A localized page contains the page content of a single language,
including the title, url path and required resources
*/
final class LocalizedPage: ObservableObject {
/**
The string to use when creating the url for the page.
Defaults to ``id`` if unset.
*/
@Published
var urlString: String
/**
The headline to use when showing the entry on it's own page
*/
@Published
var title: String
@Published
var lastModified: Date?
/**
The url used on the old version of the website.
Needed to redirect links to their new locations.
*/
let originalUrl: String?
/**
All files which occur in the content and are stored.
- Note: This property defaults to an empty set.
*/
@Published
var files: Set<String> = []
/**
All files which may occur in the content but are stored externally.
Missing files which would otherwise produce a warning are ignored when included here.
- Note: This property defaults to an empty set.
*/
@Published
var externalFiles: Set<String> = []
/**
Specifies additional files which should be copied to the destination when generating the content.
- Note: This property defaults to an empty set.
*/
@Published
var requiredFiles: Set<String> = []
@Published
var linkPreviewImage: String?
@Published
var linkPreviewTitle: String?
@Published
var linkPreviewDescription: String?
init(urlString: String,
title: String,
lastModified: Date? = nil,
originalUrl: String? = nil,
files: Set<String> = [],
externalFiles: Set<String> = [],
requiredFiles: Set<String> = [],
linkPreviewImage: String? = nil,
linkPreviewTitle: String? = nil,
linkPreviewDescription: String? = nil) {
self.urlString = urlString
self.title = title
self.lastModified = lastModified
self.originalUrl = originalUrl
self.files = files
self.externalFiles = externalFiles
self.requiredFiles = requiredFiles
self.linkPreviewImage = linkPreviewImage
self.linkPreviewTitle = linkPreviewTitle
self.linkPreviewDescription = linkPreviewDescription
}
@MainActor
func editableTitle() -> Binding<String> {
Binding(
get: {
self.title
},
set: { newValue in
self.title = newValue
}
)
}
}