diff --git a/src/web/components/posts.ts b/src/web/components/posts.ts index 50da3be..03c8a73 100644 --- a/src/web/components/posts.ts +++ b/src/web/components/posts.ts @@ -3,6 +3,17 @@ import { renderMarkdown } from '../lib/markdown' import { renderDiscussion, loadDiscussionPosts } from './discussion' import { getCurrentLang } from './mode-tabs' +// Extract text content from post content (handles both string and object formats) +function getContentText(content: unknown): string { + if (!content) return '' + if (typeof content === 'string') return content + if (typeof content === 'object' && content !== null) { + const obj = content as Record + if (typeof obj.text === 'string') return obj.text + } + return '' +} + // Format date as yyyy/mm/dd function formatDate(dateStr: string): string { const d = new Date(dateStr) @@ -52,7 +63,8 @@ export function renderPostDetail( collection: string, isOwner: boolean = false, siteUrl?: string, - appUrl: string = 'https://bsky.app' + appUrl: string = 'https://bsky.app', + canMerge: boolean = false ): string { const rkey = post.uri.split('/').pop() || '' const date = formatDate(post.value.publishedAt) @@ -61,29 +73,32 @@ export function renderPostDetail( // Build post URL for discussion search const postUrl = siteUrl ? `${siteUrl}/@${handle}/${rkey}` : `${window.location.origin}/@${handle}/${rkey}` + const rawContent = getContentText(post.value.content) + const editBtn = isOwner ? `` : '' + const mergeBtn = canMerge ? `` : '' // Get current language and show appropriate content const currentLang = getCurrentLang() const translations = post.value.translations const originalLang = post.value.langs?.[0] || 'ja' - let displayTitle = post.value.title - let displayContent = post.value.content.text + let displayTitle = post.value.title || '' + let displayContent = rawContent // Use translation if available and not original language if (translations && currentLang !== originalLang && translations[currentLang]) { const trans = translations[currentLang] - displayTitle = trans.title || post.value.title - displayContent = trans.content + displayTitle = trans.title || post.value.title || '' + displayContent = trans.content || rawContent } - const content = renderMarkdown(displayContent) + const content = displayContent ? renderMarkdown(displayContent) : '' const editForm = isOwner ? `