consolidate tags, hide date

This commit is contained in:
Christoph Hagen
2025-01-05 12:19:32 +01:00
parent 93e642c3c9
commit 5ac5a7b000
26 changed files with 284 additions and 129 deletions

View File

@ -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