- 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>
100 lines
3.5 KiB
Python
100 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Copy standalone pages and directories from archive and remap links
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
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 copy_standalone_directories():
|
|
"""Copy standalone directories like /party and /revcemetery"""
|
|
|
|
directories_to_copy = ['party', 'revcemetery', 'birthday']
|
|
copied = []
|
|
|
|
for dir_name in directories_to_copy:
|
|
src = ARCHIVE_DIR / dir_name
|
|
if src.exists() and src.is_dir():
|
|
dest = STATIC_DIR / 'legacy' / dir_name
|
|
if not dest.exists():
|
|
print(f"Copying directory: {dir_name}")
|
|
shutil.copytree(src, dest)
|
|
copied.append(dir_name)
|
|
else:
|
|
print(f"Directory already exists: {dir_name}")
|
|
copied.append(dir_name)
|
|
|
|
# Also check for any other top-level directories that might be referenced
|
|
for item in ARCHIVE_DIR.iterdir():
|
|
if item.is_dir() and item.name not in ['weblog', '.git', 'node_modules']:
|
|
# Check if it's referenced in posts
|
|
grep_cmd = f"grep -l 'ericwagoner.com/{item.name}' {POSTS_DIR}/*.md 2>/dev/null | head -1"
|
|
if os.popen(grep_cmd).read().strip():
|
|
dest = STATIC_DIR / 'legacy' / item.name
|
|
if not dest.exists():
|
|
print(f"Copying referenced directory: {item.name}")
|
|
shutil.copytree(item, dest)
|
|
copied.append(item.name)
|
|
|
|
return copied
|
|
|
|
def update_standalone_links():
|
|
"""Update links to standalone pages in posts"""
|
|
|
|
updated_count = 0
|
|
|
|
for post in POSTS_DIR.glob('*.md'):
|
|
with open(post, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
original_content = content
|
|
|
|
# Replace links to standalone directories
|
|
replacements = [
|
|
('http://www.ericwagoner.com/party', '/legacy/party'),
|
|
('http://www.ericwagoner.com/revcemetery', '/legacy/revcemetery'),
|
|
('http://www.ericwagoner.com/birthday', '/legacy/birthday'),
|
|
('http://www.ericwagoner.com/wherei', '/legacy/wherei'), # if exists
|
|
]
|
|
|
|
for old_url, new_url in replacements:
|
|
if old_url in content:
|
|
content = content.replace(old_url, new_url)
|
|
print(f" Updated link: {old_url} -> {new_url} in {post.name}")
|
|
|
|
if content != original_content:
|
|
with open(post, 'w', encoding='utf-8') as f:
|
|
f.write(content)
|
|
updated_count += 1
|
|
|
|
return updated_count
|
|
|
|
def main():
|
|
print("Migrating standalone pages and directories...")
|
|
|
|
# Copy directories
|
|
copied_dirs = copy_standalone_directories()
|
|
print(f"\n✅ Copied {len(copied_dirs)} directories: {', '.join(copied_dirs)}")
|
|
|
|
# Update links
|
|
updated = update_standalone_links()
|
|
print(f"\n✅ Updated {updated} posts with new links")
|
|
|
|
# Check remaining external links
|
|
remaining = os.popen("grep -oh 'http://www\\.ericwagoner\\.com[^\\s\\)\"]*' /Users/ericwagoner/Sites/blog/content/posts/*.md | sort -u").read()
|
|
|
|
if remaining:
|
|
print(f"\n📊 Remaining external links:")
|
|
for link in remaining.strip().split('\n'):
|
|
if link:
|
|
print(f" {link}")
|
|
else:
|
|
print("\n🎉 No more external links remain!")
|
|
|
|
if __name__ == "__main__":
|
|
main() |