# Smart Email Templates - Footer Management

## Overview

This repository contains email templates for StartEngine. We have a system for managing footers, but it requires careful manual process due to varying template structures.

## Current Situation

- **512+ email templates** across different folders
- **Multiple template structures** (some simple inline, some complex table-based)
- **Shared footer** defined in `shared/footer.html` and `shared/footer.txt`
- **Manual upload required** - Templates must be uploaded through admin UI one by one

## Available Tools

### 1. `scripts/normalize-footers.js`

Standardizes footer links (Form CRS, Disclaimer URLs) across all templates.

```bash
# Dry run to see what would change
node scripts/normalize-footers.js --dry-run

# Apply changes
node scripts/normalize-footers.js
```

**Use this when:** You need to update links in footers (like changing Form CRS URL).

### 2. `scripts/inject-shared-footer.js`

Injects the shared footer into templates that have `<!-- START FOOTER -->` and `<!-- END FOOTER -->` markers.

```bash
# Dry run
node scripts/inject-shared-footer.js --dry-run

# Apply changes
node scripts/inject-shared-footer.js

# With minification
node scripts/inject-shared-footer.js --minify
```

**Use this when:** You've manually added footer markers to templates and want to inject the shared footer.

### 3. `scripts/minify-html.js`

Minifies HTML files to reduce file size.

```bash
# Minify specific file
node scripts/minify-html.js path/to/file.html

# Minify all HTML files
node scripts/minify-html.js --all

# Dry run
node scripts/minify-html.js --all --dry-run
```

**Use this when:** You need to create minified versions of templates for production.

## How to Update Footer Content

### Current Process (Manual):

1. **Edit the shared footer**

   - HTML version: `shared/footer.html`
   - Text version: `shared/footer.txt`

2. **Identify templates to update**

   - Manually review which templates need the footer update
   - Note: Not all templates have the same structure

3. **For templates with markers:**

   ```bash
   # Inject the new footer
   node scripts/inject-shared-footer.js

   # Minify if needed
   node scripts/minify-html.js --all
   ```

4. **Upload to production**
   - Log into https://stg-marketing.startengine.com/admin
   - Go to Email Templates
   - Update each template manually through the UI
   - Test before uploading to production

### Why Manual?

- **Different structures**: Templates have varying HTML structures that can't be safely auto-detected
- **No mapping**: Folder names don't always match database template names
- **Risk**: Automated replacement could break template HTML
- **Testing required**: Each template should be reviewed after changes

## Shared Footer Structure

The `shared/footer.html` contains:

- Social media icons (Facebook, LinkedIn, Instagram, Twitter, YouTube)
- App Store and Google Play download buttons
- Legal disclaimer text
- Form CRS and Regulation Best Interest links
- Privacy policy link
- Copyright notice with template variables:
  - `[(${current_year} ?: '')]` - Current year
  - `[(${organization.name} ?: '')]` - Organization name
  - `[(${organization.full_address} ?: '')]` - Organization address

## Best Practices

1. **Always test on staging first**
2. **Use dry-run mode** before applying bulk changes
3. **Backup templates** before making changes
4. **Review rendered HTML** in browser after updates
5. **Test on multiple email clients** after upload

## Future Improvements

To enable safer bulk updates, we would need:

1. **Template structure standardization** - Ensure all templates use the same footer structure
2. **Folder-to-DB mapping file** - Create a mapping between repo folders and database template names
3. **Automated testing** - Validate HTML structure after footer replacement
4. **API authentication** - Set up proper auth for bulk uploads via API
5. **Staging validation** - Test all templates on staging before production deploy

## Notes

- The `shared/footer.html` is from the `campaign-opportunity` template
- This footer structure works for complex table-based templates
- Simpler inline templates may need a different footer structure
- Always verify footer appears correctly in rendered email before deploying
