65 lines
1.5 KiB
Swift
65 lines
1.5 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?
|
|
|
|
@Published
|
|
var linkPreviewTitle: String?
|
|
|
|
/// 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,
|
|
linkPreviewTitle: String? = nil,
|
|
originalUrl: String? = nil) {
|
|
self.content = content
|
|
self.urlComponent = urlComponent
|
|
self.name = name
|
|
self.subtitle = subtitle
|
|
self.description = description
|
|
self.linkPreviewImage = thumbnail
|
|
self.linkPreviewTitle = linkPreviewTitle
|
|
self.originalUrl = originalUrl
|
|
}
|
|
|
|
func isValid(urlComponent: String) -> Bool {
|
|
content.isValidIdForTagOrPageOrPost(urlComponent) &&
|
|
!content.containsTag(withUrlComponent: urlComponent)
|
|
}
|
|
|
|
/// The title to display when considering multiple items of this tag
|
|
var title: String {
|
|
linkPreviewTitle ?? name
|
|
}
|
|
}
|
|
|
|
extension LocalizedTag: LinkPreviewItem {
|
|
|
|
var linkPreviewDescription: String? {
|
|
description
|
|
}
|
|
}
|