Fix id of Items, saving

This commit is contained in:
Christoph Hagen
2025-06-11 08:19:44 +02:00
parent 5970ce2e9f
commit 1d0eba9d78
64 changed files with 233 additions and 217 deletions

View File

@ -118,11 +118,11 @@ final class Post: Item, DateItem, LocalizedItem {
A title for the UI, not the generation.
*/
override func title(in language: ContentLanguage) -> String {
localized(in: language).title ?? id
localized(in: language).title ?? identifier
}
func contains(_ string: String) -> Bool {
id.contains(string) ||
identifier.contains(string) ||
german.contains(string) ||
english.contains(string)
}
@ -135,11 +135,11 @@ final class Post: Item, DateItem, LocalizedItem {
@discardableResult
func update(id newId: String) -> Bool {
guard content.storage.move(post: id, to: newId) else {
print("Failed to move file of post \(id)")
guard content.storage.move(post: identifier, to: newId) else {
print("Failed to move file of post \(identifier)")
return false
}
id = newId
identifier = newId
return true
}
@ -149,10 +149,10 @@ final class Post: Item, DateItem, LocalizedItem {
}
func makePage() -> Page {
var id = self.id
var id = self.identifier
var number = 2
while !content.isNewIdForPage(id) {
id += "\(self.id)-\(number)"
id += "\(self.identifier)-\(number)"
number += 1
}
// Move tags to page
@ -210,13 +210,13 @@ extension Post: StorageItem {
createdDate: createdDate,
startDate: startDate,
endDate: endDate,
tags: tags.map { $0.id },
tags: tags.map { $0.identifier },
german: german.data,
english: english.data,
linkedPageId: linkedPage?.id)
linkedPageId: linkedPage?.identifier)
}
func saveToDisk(_ data: Data) -> Bool {
content.storage.save(post: data, for: id)
content.storage.save(post: data, for: identifier)
}
}