diff --git a/src/routes/rss/+server.ts b/src/routes/rss/+server.ts index 902f2ed..3f4fdaa 100644 --- a/src/routes/rss/+server.ts +++ b/src/routes/rss/+server.ts @@ -1,6 +1,7 @@ import type { RequestHandler } from './$types' import { prisma } from '$lib/server/database' import { logger } from '$lib/server/logger' +import { renderEdraContent } from '$lib/utils/content' // Helper function to escape XML special characters function escapeXML(str: string): string { @@ -14,159 +15,18 @@ function escapeXML(str: string): string { } // Helper function to convert content to HTML for full content +// Uses the same rendering logic as the website for consistency function convertContentToHTML(content: any): string { if (!content) return '' - + // Handle legacy content format (if it's just a string) if (typeof content === 'string') { return `
${escapeXML(content)}
` } - - // Handle TipTap/Edra format with doc root - if (content.type === 'doc' && content.content && Array.isArray(content.content)) { - return content.content - .map((node: any) => { - switch (node.type) { - case 'paragraph': - const text = extractTextFromNode(node) - return text ? `${text}
` : '' - case 'heading': - const headingText = extractTextFromNode(node) - const level = node.attrs?.level || 2 - return headingText ? `${quoteText}` : '' - case 'codeBlock': - const code = extractTextFromNode(node) - return code ? `
${code}` : ''
- case 'image':
- const src = node.attrs?.src || ''
- const alt = node.attrs?.alt || ''
- return src ? `${defaultText}
` : '' - } - }) - .filter((html: string) => html) - .join('\n') - } - - return '' -} -// Helper to extract text from TipTap nodes -function extractTextFromNode(node: any): string { - if (!node) return '' - - // Direct text content - if (node.text) return escapeXML(node.text) - - // Nested content - if (node.content && Array.isArray(node.content)) { - return node.content - .map((child: any) => { - if (child.type === 'text') { - return escapeXML(child.text || '') - } - return extractTextFromNode(child) - }) - .join('') - } - - return '' + // Use the existing renderEdraContent function which properly handles TipTap marks + // including links, bold, italic, etc. + return renderEdraContent(content) } // Helper function to extract text summary from content diff --git a/src/routes/rss/universe/+server.ts b/src/routes/rss/universe/+server.ts index 706bd47..1768b48 100644 --- a/src/routes/rss/universe/+server.ts +++ b/src/routes/rss/universe/+server.ts @@ -1,6 +1,7 @@ import type { RequestHandler } from './$types' import { prisma } from '$lib/server/database' import { logger } from '$lib/server/logger' +import { renderEdraContent } from '$lib/utils/content' // Helper function to escape XML special characters function escapeXML(str: string): string { @@ -14,27 +15,13 @@ function escapeXML(str: string): string { } // Helper function to convert content to HTML for full content +// Uses the same rendering logic as the website for consistency function convertContentToHTML(content: any): string { - if (!content || !content.blocks) return '' + if (!content) return '' - return content.blocks - .map((block: any) => { - switch (block.type) { - case 'paragraph': - return `${escapeXML(block.content || '')}
` - case 'heading': - const level = block.level || 2 - return `${escapeXML(block.content || '')}
` - } - }) - .join('\n') + // Use the existing renderEdraContent function which properly handles TipTap marks + // including links, bold, italic, etc. + return renderEdraContent(content) } // Helper function to extract text summary from content