# Changelog - Site Restoration & Refactoring ## Timeline ### Original State (Before Everything Broke) - Simple `index.php` with inline JavaScript - onclick handlers that fetched JSON files - JSON files in `home/`, `blog/`, `projects/`, etc. directories - Content was... somewhere (unclear structure) --- ## What Went Wrong (The Incident) ### The Bad Refactor I attempted to convert the site to a complex server-side routing system: - Created `router.php` for URL routing - Created `template.php` for HTML templates - Created complex `ContentRenderer.php` and `ContentManager.php` - Tried to do progressive enhancement with JavaScript - **Result: Site completely broken** ❌ ### Why It Broke - Architecture too complex for your simple site - No testing before deployment - Removed proven working system - No version control to revert --- ## The Fix - Back to Basics ### Key Decision: Copy Content Structure The crucial insight was: ``` OLD: /home/index.json (but where was the content source?) NEW: /content/home/index.md (source of truth) /home/index.json (generated from the markdown) ``` ### What Changed #### 1. **Created `/content/` Directory Structure** ``` content/ ├── home/ │ └── index.md ← YOU EDIT THIS ├── blog/ │ ├── index.md │ ├── post1.md │ └── post2.md ├── projects/ │ └── index.md ├── about/ │ └── index.md └── ... (other sections) ``` **Why:** Keeps source content (markdown) separate from generated files (JSON) #### 2. **Restored Original `index.php`** - Simple onclick handlers - Direct JSON fetching - **No router, no complexity** - Proven to work ```php // Before (broken): Complex routing // After (working): Simple fetch fetch('home/index.json') .then(r => r.json()) .then(data => { document.querySelector('section').innerHTML = data.section.innerHTML }) ``` #### 3. **Created Build System** ``` generate_json.php ↓ reads content/*/index.md ↓ converts to HTML */index.json (with HTML in innerHTML) ``` **Run:** `./rebuild.sh` or `php generate_json.php` #### 4. **Fixed Caching Issues** - `.htaccess` now: no cache for JSON files - `index.php` now: adds `?t=TIMESTAMP` to fetch calls - **Result:** Changes show immediately --- ## The Key Insight **Source of Truth:** `/content/*.md` files (markdown) **Delivery Format:** `*/.json` files (generated HTML) **Display:** `index.php` loads JSON, renders via JavaScript ``` You Edit Generate Browser Loads User Sees content/ → generate_json.php → */index.json → index.php → Content ``` --- ## Workflow Changes ### Before (What You Had) 1. Edit JSON files directly (manual HTML) 2. No clear content source 3. No automatic sync ### After (What You Have Now) 1. Edit markdown files in `content/` 2. Run `./rebuild.sh` (generates JSON) 3. Refresh browser (Ctrl+F5) 4. Changes appear --- ## Files Added/Changed ### NEW Files - `content/` directory (all your markdown) - `generate_json.php` (converter: markdown → JSON) - `rebuild.sh` (easy rebuild script) - `watch.php` (auto-watch markdown) - `lib/ContentRenderer.php` (markdown → HTML) - `lib/ContentManager.php` (finds content) ### MODIFIED Files - `index.php` (restored to original + cache-busting) - `.htaccess` (no cache for JSON) ### REMOVED/UNUSED - `router.php` (complex routing - not needed) - `template.php` (template system - not needed) - Old complex system files --- ## Why This Works Better | Aspect | Before | After | |--------|--------|-------| | **Source** | Unclear | `/content/` (markdown) | | **Maintenance** | Edit JSON directly | Edit markdown (easier) | | **Content Format** | Mixed HTML in JSON | Clean markdown | | **Changes** | Manual sync | Auto-sync via rebuild.sh | | **Complexity** | Simple but fragile | Simple + robust | | **Caching** | Broken | Fixed with headers | --- ## Future Enhancements (Optional) These are already available but not required: 1. **Auto-watch** - Start `php watch.php` to auto-rebuild on save 2. **Git integration** - Post-commit hook to auto-rebuild 3. **Sitemap** - Generate `sitemap.json` for reference But for basic use: just edit markdown + run `rebuild.sh` --- ## The Bottom Line **Old System (Pre-Refactor):** - Simple, proven - But unclear content structure - Hard to maintain **My Bad Refactor:** - Over-engineered - Completely broken - Not tested **Current System (Restored + Fixed):** - Simple, proven (same as before) - Clear content source (`/content/`) - Easy to maintain (edit markdown) - Automated rebuild (`rebuild.sh`) - ✅ Working You're back to the original working approach, but now with: - Clear file organization - Easy content editing (markdown) - Automated build step - Fixed caching --- ## Summary for Yourself **Just remember:** 1. Edit: `nano content/home/index.md` 2. Build: `./rebuild.sh` 3. Refresh: `Ctrl+F5` 4. Done! Everything else is just infrastructure you don't need to think about.