Files
kestrelsnest-blog/fix_remaining_links.py
Eric Wagoner eddd9d2a80 Import WordPress posts and migrate standalone content to Hugo
- Successfully imported 1731 WordPress posts to Hugo markdown format
- Migrated 204+ images from archive to static directory
- Copied standalone directories (curtain, farm, gobbler, house, images, party, revcemetery, railsday, birthday)
- Fixed all internal links to use /legacy prefix for archived content
- Remapped archive links to point to correct Hugo posts
- Fixed Louisville Georgia Cemetery post rendering issue

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-23 16:23:40 -04:00

70 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""
Fix remaining ericwagoner.com links in posts
"""
import os
import re
from pathlib import Path
POSTS_DIR = Path('/Users/ericwagoner/Sites/blog/content/posts')
ARCHIVE_DIR = Path('/Users/ericwagoner/Sites/ericwagoner.com')
STATIC_DIR = Path('/Users/ericwagoner/Sites/blog/static')
def find_and_fix_links():
"""Find and fix all remaining external links"""
fixed_count = 0
for post in POSTS_DIR.glob('*.md'):
with open(post, 'r', encoding='utf-8') as f:
content = f.read()
original_content = content
# Find all links to ericwagoner.com (both in markdown links and href)
pattern = r'http://www\.ericwagoner\.com(/[^)\s"]*(?:jpg|jpeg|gif|png))'
def replace_link(match):
path = match.group(1)
# Check if we already copied this file
legacy_path = STATIC_DIR / 'images' / 'legacy' / path.lstrip('/')
if legacy_path.exists():
return f'/images/legacy{path}'
# Try to find in archive
archive_path = ARCHIVE_DIR / path.lstrip('/')
if not archive_path.exists() and '/weblog/' in path:
# Try without weblog
alt_path = path.replace('/weblog/', '/', 1)
archive_path = ARCHIVE_DIR / alt_path.lstrip('/')
if archive_path.exists():
# Copy it
legacy_path.parent.mkdir(parents=True, exist_ok=True)
import shutil
try:
shutil.copy2(archive_path, legacy_path)
return f'/images/legacy{path}'
except:
pass
# Keep original if we can't find/copy it
return match.group(0)
# Replace all image links
content = re.sub(pattern, replace_link, content)
if content != original_content:
with open(post, 'w', encoding='utf-8') as f:
f.write(content)
fixed_count += 1
print(f"Fixed {post.name}")
return fixed_count
if __name__ == "__main__":
print("Fixing remaining image links...")
count = find_and_fix_links()
print(f"✅ Fixed {count} posts")