Enhance content parsing and metadata extraction in HTMLContentRenderer and ToggleTableRow
- Improved HTMLContentRenderer to better handle JSON content and extract HTML safely. - Updated ToggleTableRow to robustly extract meta descriptions, including parsing potential JSON strings. - Refactored Content page to conditionally display meta descriptions based on JSON parsing results, enhancing user experience.
This commit is contained in:
@@ -132,11 +132,23 @@ export default function Content() {
|
||||
<div className="font-medium text-gray-900 dark:text-white">
|
||||
{item.meta_title || item.title || item.task_title || `Task #${item.task}`}
|
||||
</div>
|
||||
{item.meta_description && (
|
||||
<div className="mt-1 text-sm text-gray-500 dark:text-gray-400 line-clamp-2">
|
||||
{item.meta_description}
|
||||
</div>
|
||||
)}
|
||||
{(() => {
|
||||
let metaDesc = item.meta_description;
|
||||
// If meta_description is a JSON string, extract the actual value
|
||||
if (metaDesc && typeof metaDesc === 'string' && metaDesc.trim().startsWith('{')) {
|
||||
try {
|
||||
const parsed = JSON.parse(metaDesc);
|
||||
metaDesc = parsed.meta_description || metaDesc;
|
||||
} catch {
|
||||
// Not valid JSON, use as-is
|
||||
}
|
||||
}
|
||||
return metaDesc ? (
|
||||
<div className="mt-1 text-sm text-gray-500 dark:text-gray-400 line-clamp-2">
|
||||
{metaDesc}
|
||||
</div>
|
||||
) : null;
|
||||
})()}
|
||||
</td>
|
||||
<td className="px-5 py-4 align-top">
|
||||
{item.primary_keyword ? (
|
||||
|
||||
Reference in New Issue
Block a user