ChWebsiteApp/CHDataManagement/Model/LocalizedTag.swift
2025-01-04 08:44:26 +01:00

59 lines
1.3 KiB
Swift

import Foundation
final class LocalizedTag: ObservableObject {
unowned let content: Content
@Published
var urlComponent: String
/// A custom name, different from the tag id
@Published
var name: String
@Published
var subtitle: String?
@Published
var description: String?
/// The image id of the thumbnail
@Published
var linkPreviewImage: FileResource?
/// The original url in the previous site layout
let originalUrl: String?
init(content: Content,
urlComponent: String,
name: String,
subtitle: String? = nil,
description: String? = nil,
thumbnail: FileResource? = nil,
originalUrl: String? = nil) {
self.content = content
self.urlComponent = urlComponent
self.name = name
self.subtitle = subtitle
self.description = description
self.linkPreviewImage = thumbnail
self.originalUrl = originalUrl
}
func isValid(urlComponent: String) -> Bool {
content.isValidIdForTagOrPageOrPost(urlComponent) &&
!content.containsTag(withUrlComponent: urlComponent)
}
}
extension LocalizedTag: LinkPreviewItem {
var linkPreviewTitle: String? {
self.name
}
var linkPreviewDescription: String? {
description
}
}