fix: better handling of draft and published posts in preview

This commit is contained in:
2026-02-16 22:20:31 +01:00
parent 201a74f447
commit 4ce1654f47
4 changed files with 328 additions and 22 deletions

View File

@@ -1049,6 +1049,36 @@ export class PostEngine extends EventEmitter {
return !!(dbPost && dbPost.filePath && dbPost.filePath !== '');
}
async getPublishedVersion(id: string): Promise<PostData | null> {
const db = getDatabase().getLocal();
const dbPost = await db.select().from(posts).where(eq(posts.id, id)).get();
if (!dbPost || !dbPost.filePath) {
return null;
}
const fileData = await this.readPostFile(dbPost.filePath);
if (!fileData) {
return null;
}
return {
id: dbPost.id,
projectId: dbPost.projectId,
title: fileData.title,
slug: fileData.slug,
excerpt: fileData.excerpt,
content: fileData.content,
status: 'published',
author: fileData.author,
createdAt: fileData.createdAt,
updatedAt: fileData.updatedAt,
publishedAt: fileData.publishedAt ?? dbPost.publishedAt ?? undefined,
tags: fileData.tags,
categories: fileData.categories,
};
}
/**
* Rebuild the FTS index for all posts in the current project.
* Call this after changing the search language or after migration.