Files
kestrelsnest-blog/fix_standalone_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

66 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""
Fix links to standalone directories to include /legacy prefix
"""
import re
from pathlib import Path
POSTS_DIR = Path('/Users/ericwagoner/Sites/blog/content/posts')
def fix_standalone_links():
"""Fix links to standalone directories"""
# Directories that were copied to /legacy
standalone_dirs = ['curtain', 'farm', 'gobbler', 'house', 'images', 'railsday', 'birthday', 'party', 'revcemetery']
fixed_count = 0
total_fixes = 0
for post in POSTS_DIR.glob('*.md'):
with open(post, 'r', encoding='utf-8') as f:
content = f.read()
original_content = content
for dir_name in standalone_dirs:
# Fix links like ](/curtain/) to ](/legacy/curtain/)
pattern = f'](/{dir_name}/'
replacement = f'](/legacy/{dir_name}/'
if pattern in content:
content = content.replace(pattern, replacement)
print(f" Fixed: {pattern} -> {replacement} in {post.name}")
total_fixes += 1
# Also fix links like href="/curtain/"
pattern = f'href="/{dir_name}/'
replacement = f'href="/legacy/{dir_name}/'
if pattern in content:
content = content.replace(pattern, replacement)
print(f" Fixed: {pattern} -> {replacement} in {post.name}")
total_fixes += 1
# And src="/images/
if dir_name == 'images':
pattern = f'src="/{dir_name}/'
replacement = f'src="/legacy/{dir_name}/'
if pattern in content:
content = content.replace(pattern, replacement)
print(f" Fixed: {pattern} -> {replacement} in {post.name}")
total_fixes += 1
if content != original_content:
with open(post, 'w', encoding='utf-8') as f:
f.write(content)
fixed_count += 1
return fixed_count, total_fixes
def main():
print("Fixing standalone directory links...")
posts_fixed, links_fixed = fix_standalone_links()
print(f"\n✅ Fixed {links_fixed} links in {posts_fixed} posts")
if __name__ == "__main__":
main()