# FAQ Content Separation Fix

**Date:** 2026-01-14  
**Status:** ✅ Completed

## Problem

FAQs were incorrectly being added to blog post `content.html` when they should only exist in the `faqs` array. The blog template system (`BlogFAQ.php`) renders FAQs separately from the main content, so having FAQs in `content.html` caused:

1. **Duplicate FAQ sections** - FAQs appeared both in the main content and in the dedicated FAQ section
2. **Incorrect structure** - FAQs should be stored only in the structured `faqs` array
3. **Template confusion** - The template expects FAQs only from the `faqs` array

## Root Cause

The `add-faqs-to-post.php` script was incorrectly adding FAQ HTML to `content.html` instead of only updating the `faqs` array.

## Solution

### 1. Created Cleanup Script

**File:** `v2/scripts/blog/remove-faqs-from-content.php`

- Removes FAQ sections from `content.html` in all blog posts
- Preserves FAQs in the `faqs` array
- Supports dry-run mode for testing
- Processes all posts or specific post/category

**Usage:**
```bash
# Dry run (test without modifying files)
php v2/scripts/blog/remove-faqs-from-content.php --dry-run

# Remove FAQs from all posts
php v2/scripts/blog/remove-faqs-from-content.php

# Remove FAQs from specific post
php v2/scripts/blog/remove-faqs-from-content.php --post=slug --category=category
```

### 2. Fixed add-faqs-to-post.php Script

**File:** `v2/scripts/blog/add-faqs-to-post.php`

**Changes:**
- ✅ Now only updates the `faqs` array (does NOT add to HTML)
- ✅ Removes any existing FAQ sections from HTML content
- ✅ Preserves FAQs in structured format only
- ✅ Updated modified_date when changes are made

**Key Changes:**
- Removed code that generated FAQ HTML and added it to `content.html`
- Added code to remove FAQ sections from HTML if present
- FAQs are now stored only in the `faqs` array

## Results

### Posts Affected

- **Total posts checked:** 99
- **Posts with FAQs in HTML:** 1 (`recap-webinar-sv-pruefung`)
- **Bytes removed:** 6,475 bytes

### Verification

✅ FAQs removed from `content.html`  
✅ FAQs preserved in `faqs` array  
✅ Template renders FAQs correctly from `faqs` array  
✅ No duplicate FAQ sections  

## Correct Structure

### ✅ Correct: FAQs in `faqs` array only

```json
{
  "content": {
    "html": "<div>...main content without FAQs...</div>"
  },
  "faqs": [
    {
      "question": "Question text",
      "answer": "Answer text"
    }
  ]
}
```

### ❌ Incorrect: FAQs in both places

```json
{
  "content": {
    "html": "<div>...main content...<h2>FAQ</h2><div class=\"schema-faq\">...</div></div>"
  },
  "faqs": [...]
}
```

## Template Rendering

The blog post template (`v2/pages/blog/post.php`) renders FAQs separately:

1. **Main content** is rendered from `content.html` via `PostContent.php`
2. **FAQs** are rendered separately from `faqs` array via `BlogFAQ.php` component

This separation allows:
- Better SEO (FAQPage schema markup)
- Improved UX (dedicated FAQ section)
- Easier maintenance (structured data)

## Prevention

The updated `add-faqs-to-post.php` script now:
- ✅ Only updates the `faqs` array
- ✅ Removes FAQ sections from HTML if present
- ✅ Prevents future duplication

## Related Files

- `v2/scripts/blog/remove-faqs-from-content.php` - Cleanup script
- `v2/scripts/blog/add-faqs-to-post.php` - Fixed FAQ addition script
- `v2/pages/blog/post.php` - Blog post template
- `v2/components/blog/BlogFAQ.php` - FAQ rendering component

## Next Steps

When adding FAQs to posts:
1. Use `add-faqs-to-post.php` script (now fixed)
2. FAQs will be added only to `faqs` array
3. HTML content will be cleaned automatically
4. FAQs will render via `BlogFAQ.php` component
