consolidate tags, hide date
This commit is contained in:
@ -17,6 +17,12 @@ final class Post: Item {
|
||||
@Published
|
||||
var endDate: Date
|
||||
|
||||
/**
|
||||
The tags associated with the post
|
||||
|
||||
This list is only used if ``linkedPage`` is `nil`,
|
||||
otherwise the tag list of the linked page is used.
|
||||
*/
|
||||
@Published
|
||||
var tags: [Tag]
|
||||
|
||||
@ -52,6 +58,55 @@ final class Post: Item {
|
||||
super.init(content: content, id: id)
|
||||
}
|
||||
|
||||
// MARK: Tags
|
||||
|
||||
func usedTags() -> [Tag] {
|
||||
linkedPage?.tags ?? tags
|
||||
}
|
||||
|
||||
/**
|
||||
Check if a tag is associated with this post.
|
||||
|
||||
If the post is linked to a page, then the tags of the page are checked.
|
||||
*/
|
||||
func contains(_ tag: Tag) -> Bool {
|
||||
guard let linkedPage else {
|
||||
return tags.contains(tag)
|
||||
}
|
||||
return linkedPage.tags.contains(tag)
|
||||
}
|
||||
|
||||
func toggle(_ tag: Tag) {
|
||||
if let linkedPage {
|
||||
linkedPage.toggle(tag)
|
||||
return
|
||||
}
|
||||
guard let index = tags.firstIndex(of: tag) else {
|
||||
tags.append(tag)
|
||||
return
|
||||
}
|
||||
tags.remove(at: index)
|
||||
}
|
||||
|
||||
func remove(_ tag: Tag) {
|
||||
if let linkedPage {
|
||||
linkedPage.remove(tag)
|
||||
return
|
||||
}
|
||||
tags.remove(tag)
|
||||
}
|
||||
|
||||
func associate(_ tag: Tag) {
|
||||
if let linkedPage {
|
||||
linkedPage.associate(tag)
|
||||
return
|
||||
}
|
||||
guard !tags.contains(tag) else {
|
||||
return
|
||||
}
|
||||
tags.append(tag)
|
||||
}
|
||||
|
||||
func localized(in language: ContentLanguage) -> LocalizedPost {
|
||||
switch language {
|
||||
case .english: return english
|
||||
|
Reference in New Issue
Block a user