feat: Add headless template type
This commit is contained in:
@@ -2,3 +2,4 @@ export * from './schemas/index.js';
|
||||
export * from './operators.js';
|
||||
export * from './template.js';
|
||||
export * from './i18n/index.js';
|
||||
export * from './unsubscribe.js';
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Detects whether an email body contains an unsubscribe signal.
|
||||
*
|
||||
* Used to warn authors of HEADLESS emails that no unsubscribe mechanism
|
||||
* was found — Plunk cannot verify the link works, but can check for common patterns.
|
||||
*
|
||||
* Returns true if any of the following are present:
|
||||
* - Plunk template variables: {{unsubscribeUrl}} or {{manageUrl}}
|
||||
* - An <a> tag whose href contains unsubscribe-related keywords
|
||||
* - An <a> tag whose visible text contains unsubscribe-related keywords
|
||||
*/
|
||||
export function detectUnsubscribeSignal(body: string): boolean {
|
||||
if (!body) return false;
|
||||
|
||||
// Plunk's own managed unsubscribe variables
|
||||
if (/\{\{(?:unsubscribeUrl|manageUrl)\}\}/.test(body)) return true;
|
||||
|
||||
// href containing unsubscribe keywords
|
||||
if (/href=["'][^"']*(?:unsubscribe|opt[_-]?out|remove)[^"']*["']/i.test(body)) return true;
|
||||
|
||||
// Anchor text containing unsubscribe keywords
|
||||
if (/<a\b[^>]*>(?:[^<]*(?:unsubscribe|opt[_-]?\s*out|manage\s+preferences|email\s+preferences|remove\s+me)[^<]*)<\/a>/i.test(body))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user