import type {ReadonlyDeep} from 'type-fest'; type EmailTemplateData = ReadonlyDeep<{ result: { data?: { errors?: unknown[]; }; }; siteUrl: URL; postsUrl: URL; emailRecipient: string; }>; const escapeHtml = (value: string): string => value .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); const getErrorMessage = (importError: unknown): string => { if (importError && typeof importError === 'object' && 'message' in importError && typeof importError.message === 'string' && importError.message) { return importError.message; } return 'Unknown error'; }; const MAX_LISTED_ERRORS = 5; const renderErrorList = (importErrors: ReadonlyDeep): string => { const items = importErrors .slice(0, MAX_LISTED_ERRORS) .map((importError: unknown) => `
  • ${escapeHtml(getErrorMessage(importError))}
  • `); const remaining = importErrors.length - MAX_LISTED_ERRORS; if (remaining > 0) { items.push(`
  • and ${remaining} more — check the server logs for the full list
  • `); } return items.join('\n '); }; export const emailTemplate = ({result, siteUrl, postsUrl, emailRecipient}: EmailTemplateData): string => { const importErrors = result?.data?.errors; return ` Your content import is complete
     
    ${importErrors ? ` ` : ` `}

    ${importErrors ? 'Import unsuccessful' : 'Your content import has finished successfully'}

    One or more errors occurred while importing your content:

      ${renderErrorList(importErrors)}

    Please fix the listed issues and try again, or ask for help on the Ghost Community Forum.

    View posts
     
    `; };