|
| 1 | +import i18nData from "./messages.json" with { type: "json" }; |
| 2 | + |
| 3 | +const LOGO_URL = Deno.env.get("LOGO_URL"); |
| 4 | +const FRONTEND_HOST = Deno.env.get("FRONTEND_HOST"); |
| 5 | + |
| 6 | +/** |
| 7 | + * Simple template interpolator: replaces {var} with provided values |
| 8 | + */ |
| 9 | +export function t( |
| 10 | + template: string, |
| 11 | + vars: Record<string, string | number> = {}, |
| 12 | +): string { |
| 13 | + return template.replace(/{(\w+)}/g, (_, key) => String(vars[key] ?? "")); |
| 14 | +} |
| 15 | + |
| 16 | +export function fillTemplate( |
| 17 | + headerTitle: string, |
| 18 | + bodyContent: string, |
| 19 | + headerSubtitle = "", |
| 20 | + language: "en" | "fr" = "en", |
| 21 | +) { |
| 22 | + const i18n = (i18nData as any)[language]; |
| 23 | + |
| 24 | + return ` |
| 25 | + <!DOCTYPE html> |
| 26 | +<html lang="${language}"> |
| 27 | + <head> |
| 28 | + <meta charset="UTF-8" /> |
| 29 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 30 | + <title>${headerTitle}</title> |
| 31 | + <link |
| 32 | + href="https://fonts.googleapis.com/css2?family=Lexend+Deca:wght@400;600;700&family=Merriweather:wght@700&display=swap" |
| 33 | + rel="stylesheet" |
| 34 | + /> |
| 35 | + </head> |
| 36 | + <body |
| 37 | + style=" |
| 38 | + margin: 0; |
| 39 | + background-color: #f9fafb; |
| 40 | + color: #111827; |
| 41 | + font-family: 'Lexend Deca', Arial, sans-serif; |
| 42 | + -webkit-font-smoothing: antialiased; |
| 43 | + " |
| 44 | + > |
| 45 | + <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="padding: 40px 0"> |
| 46 | + <tr> |
| 47 | + <td align="center"> |
| 48 | + <table |
| 49 | + width="600" |
| 50 | + cellpadding="0" |
| 51 | + cellspacing="0" |
| 52 | + role="presentation" |
| 53 | + style=" |
| 54 | + background: #ffffff; |
| 55 | + border-radius: 12px; |
| 56 | + overflow: hidden; |
| 57 | + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); |
| 58 | + " |
| 59 | + > |
| 60 | + <!-- Logo --> |
| 61 | + <tr> |
| 62 | + <td align="center" style="padding: 20px 0"> |
| 63 | + <a href="${FRONTEND_HOST}" target="_blank" style="display: inline-block; text-decoration: none"> |
| 64 | + <img |
| 65 | + src="${LOGO_URL}" |
| 66 | + alt="Leadminer" |
| 67 | + title="Leadminer Logo" |
| 68 | + border="0" |
| 69 | + style="display: block; height: 3.125rem; width: auto" |
| 70 | + /> |
| 71 | + </a> |
| 72 | + </td> |
| 73 | + </tr> |
| 74 | +
|
| 75 | + <!-- Header --> |
| 76 | + <tr> |
| 77 | + <td style="text-align: center"> |
| 78 | + <h1 |
| 79 | + style=" |
| 80 | + margin: 0; |
| 81 | + font-size: 26px; |
| 82 | + font-family: 'Merriweather', serif; |
| 83 | + font-weight: 700; |
| 84 | + " |
| 85 | + > |
| 86 | + ${headerTitle} |
| 87 | + </h1> |
| 88 | + <p style="margin: 10px 0 0; font-size: 16px; color: #374151"> |
| 89 | + ${headerSubtitle} |
| 90 | + </p> |
| 91 | + </td> |
| 92 | + </tr> |
| 93 | +
|
| 94 | + <!-- Body --> |
| 95 | + <tr> |
| 96 | + <td style="padding: 36px 32px"> |
| 97 | + ${bodyContent} |
| 98 | + </td> |
| 99 | + </tr> |
| 100 | +
|
| 101 | + <!-- Footer --> |
| 102 | + <tr> |
| 103 | + <td |
| 104 | + style=" |
| 105 | + background: #f3f4f6; |
| 106 | + text-align: center; |
| 107 | + padding: 28px; |
| 108 | + font-size: 13px; |
| 109 | + color: #6b7280; |
| 110 | + " |
| 111 | + > |
| 112 | + <p style="margin: 0 0 4px"> |
| 113 | + ${i18n.footer.line1} |
| 114 | + <strong> |
| 115 | + <a |
| 116 | + style="color: #6b7280; text-decoration: none" |
| 117 | + href="${FRONTEND_HOST}" |
| 118 | + > |
| 119 | + ${i18n.footer.brand} |
| 120 | + </a> |
| 121 | + </strong> |
| 122 | + . |
| 123 | + </p> |
| 124 | + <p style="margin: 6px 0 0; color: #9ca3af"> |
| 125 | + ${i18n.footer.line2} |
| 126 | + </p> |
| 127 | + </td> |
| 128 | + </tr> |
| 129 | + </table> |
| 130 | + </td> |
| 131 | + </tr> |
| 132 | + </table> |
| 133 | + </body> |
| 134 | +</html> |
| 135 | +`; |
| 136 | +} |
0 commit comments