First version
This commit is contained in:
89
CHDataManagement/Model/Page.swift
Normal file
89
CHDataManagement/Model/Page.swift
Normal file
@ -0,0 +1,89 @@
|
||||
import Foundation
|
||||
|
||||
final class Page: ObservableObject {
|
||||
|
||||
/**
|
||||
The unique id of the entry
|
||||
*/
|
||||
@Published
|
||||
var id: String
|
||||
|
||||
@Published
|
||||
var isDraft: Bool
|
||||
|
||||
@Published
|
||||
var metadata: [LocalizedPage]
|
||||
|
||||
/**
|
||||
All files which may occur in content but is 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> = []
|
||||
|
||||
/**
|
||||
Additional images required by the element.
|
||||
|
||||
These images are specified as: `source_name destination_name width (height)`.
|
||||
*/
|
||||
@Published
|
||||
var images: Set<String> = []
|
||||
|
||||
init(id: String, isDraft: Bool, metadata: [LocalizedPage], externalFiles: Set<String> = [], requiredFiles: Set<String> = [], images: Set<String> = []) {
|
||||
self.id = id
|
||||
self.isDraft = isDraft
|
||||
self.metadata = metadata
|
||||
self.externalFiles = externalFiles
|
||||
self.requiredFiles = requiredFiles
|
||||
self.images = images
|
||||
}
|
||||
|
||||
func metadata(for language: ContentLanguage) -> LocalizedPage? {
|
||||
metadata.first { $0.language == language }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct LocalizedPage {
|
||||
|
||||
let language: ContentLanguage
|
||||
|
||||
/**
|
||||
The string to use when creating the url for the page.
|
||||
|
||||
Defaults to ``id`` if unset.
|
||||
*/
|
||||
var urlString: String?
|
||||
|
||||
/**
|
||||
The headline to use when showing the entry on it's own page
|
||||
*/
|
||||
var headline: String
|
||||
}
|
||||
|
||||
extension Page: Identifiable {
|
||||
|
||||
}
|
||||
|
||||
extension Page: Equatable {
|
||||
|
||||
static func == (lhs: Page, rhs: Page) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
}
|
||||
|
||||
extension Page: Hashable {
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user