fix: post creation working again, also slugs

This commit is contained in:
2026-02-10 16:50:45 +01:00
parent 3f0c767809
commit 5c10ed3fd5
7 changed files with 106 additions and 17 deletions

View File

@@ -232,7 +232,7 @@ export class PostEngine extends EventEmitter {
const post: PostData = {
id,
projectId: data.projectId || this.currentProjectId,
title: data.title || 'Untitled',
title: data.title ?? '',
slug,
excerpt: data.excerpt,
content: data.content || '',
@@ -303,11 +303,18 @@ export class PostEngine extends EventEmitter {
newStatus = 'draft';
}
// Auto-update slug when title changes, but only if post was never published
let newSlug = data.slug ?? existing.slug;
if (data.title !== undefined && data.title !== existing.title && !existing.publishedAt) {
newSlug = await this.generateUniqueSlug(data.title || 'untitled', id);
}
const updated: PostData = {
...existing,
...data,
id, // Ensure ID doesn't change
projectId: existing.projectId, // Ensure projectId doesn't change
slug: newSlug,
status: newStatus as 'draft' | 'published' | 'archived',
updatedAt: new Date(),
};