consolidate tags, hide date
This commit is contained in:
@ -34,8 +34,10 @@ extension Content {
|
||||
func check(content: String, of page: Page, for language: ContentLanguage, onComplete: @escaping (PageGenerationResults) -> Void) {
|
||||
performGenerationIfIdle {
|
||||
let results = self.results.makeResults(for: page, in: language)
|
||||
results.reset()
|
||||
let generator = PageContentParser(content: page.content, language: language, results: results)
|
||||
_ = generator.generatePage(from: content)
|
||||
self.results.recalculate()
|
||||
DispatchQueue.main.async {
|
||||
onComplete(results)
|
||||
}
|
||||
@ -227,7 +229,7 @@ extension Content {
|
||||
for language in ContentLanguage.allCases {
|
||||
let results = results.makeResults(for: tag, in: language)
|
||||
|
||||
let posts = posts.filter { $0.tags.contains(tag) }
|
||||
let posts = posts.filter { $0.contains(tag) }
|
||||
guard posts.count > 0 else { continue }
|
||||
|
||||
let source = TagPageGeneratorSource(
|
||||
|
@ -180,6 +180,7 @@ extension Content {
|
||||
externalLink: page.externalLink,
|
||||
isDraft: page.isDraft,
|
||||
createdDate: page.createdDate,
|
||||
hideDate: page.hideDate ?? false,
|
||||
startDate: page.startDate,
|
||||
endDate: page.endDate,
|
||||
german: convert(page.german, images: files),
|
||||
|
@ -59,6 +59,7 @@ private extension Page {
|
||||
.init(isDraft: isDraft,
|
||||
externalLink: externalLink,
|
||||
tags: tags.map { $0.id },
|
||||
hideDate: hideDate ? true : nil,
|
||||
createdDate: createdDate,
|
||||
startDate: startDate,
|
||||
endDate: hasEndDate ? endDate : nil,
|
||||
|
@ -49,6 +49,11 @@ final class LocalizedTag: ObservableObject {
|
||||
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 {
|
||||
|
@ -17,6 +17,9 @@ final class Page: Item {
|
||||
@Published
|
||||
var createdDate: Date
|
||||
|
||||
@Published
|
||||
var hideDate: Bool
|
||||
|
||||
@Published
|
||||
var startDate: Date
|
||||
|
||||
@ -46,6 +49,7 @@ final class Page: Item {
|
||||
externalLink: String?,
|
||||
isDraft: Bool,
|
||||
createdDate: Date,
|
||||
hideDate: Bool,
|
||||
startDate: Date,
|
||||
endDate: Date?,
|
||||
german: LocalizedPage,
|
||||
@ -55,6 +59,7 @@ final class Page: Item {
|
||||
self.externalLink = externalLink
|
||||
self.isDraft = isDraft
|
||||
self.createdDate = createdDate
|
||||
self.hideDate = hideDate
|
||||
self.startDate = startDate
|
||||
self.hasEndDate = endDate != nil
|
||||
self.endDate = endDate ?? startDate
|
||||
@ -86,6 +91,34 @@ final class Page: Item {
|
||||
externalLink != nil
|
||||
}
|
||||
|
||||
// MARK: Tags
|
||||
|
||||
/**
|
||||
Check if a tag is associated with this page
|
||||
*/
|
||||
func contains(_ tag: Tag) -> Bool {
|
||||
tags.contains(tag)
|
||||
}
|
||||
|
||||
func toggle(_ tag: Tag) {
|
||||
guard let index = tags.firstIndex(of: tag) else {
|
||||
tags.append(tag)
|
||||
return
|
||||
}
|
||||
tags.remove(at: index)
|
||||
}
|
||||
|
||||
func remove(_ tag: Tag) {
|
||||
tags.remove(tag)
|
||||
}
|
||||
|
||||
func associate(_ tag: Tag) {
|
||||
guard !tags.contains(tag) else {
|
||||
return
|
||||
}
|
||||
tags.append(tag)
|
||||
}
|
||||
|
||||
// MARK: Paths
|
||||
|
||||
override func absoluteUrl(in language: ContentLanguage) -> String {
|
||||
|
@ -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
|
||||
|
@ -56,7 +56,7 @@ final class Tag: Item {
|
||||
}
|
||||
|
||||
override func title(in language: ContentLanguage) -> String {
|
||||
localized(in: language).name
|
||||
localized(in: language).title
|
||||
}
|
||||
|
||||
override var itemType: ItemType {
|
||||
|
Reference in New Issue
Block a user