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

67 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""
Replace thumbnail images with full-size images in posts
"""
import re
from pathlib import Path
POSTS_DIR = Path('/Users/ericwagoner/Sites/blog/content/posts')
def replace_thumbnails():
"""Replace thumbnail links with full-size images"""
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
# Pattern to find linked images: [![alt text](thumbnail)](full-size)
# Replace with just the full-size image: ![alt text](full-size)
pattern = r'\[\!\[([^\]]*)\]\(([^\)]*thumb[^\)]*)\)\]\(([^\)]+)\)'
def replace_match(match):
alt_text = match.group(1)
thumbnail = match.group(2)
full_size = match.group(3)
# Use the alt text with the full-size image
return f'![{alt_text}]({full_size})'
content = re.sub(pattern, replace_match, content)
# Also handle cases where there might be variations in the pattern
# Pattern for images that have "thumb" in the filename
pattern2 = r'!\[([^\]]*)\]\(([^\)]*thumb[^\)]*\.(?:jpg|jpeg|gif|png))\)'
def replace_thumb_with_full(match):
alt_text = match.group(1)
thumb_path = match.group(2)
# Remove 'thumb' from the filename to get the full-size version
full_path = re.sub(r'thumb(?=\.|_)', '', thumb_path)
# Check if we're just removing 'thumb' would give us a valid path
# If the path doesn't change, keep it as is
if full_path != thumb_path:
return f'![{alt_text}]({full_path})'
return match.group(0)
content = re.sub(pattern2, replace_thumb_with_full, content, flags=re.IGNORECASE)
if content != original_content:
with open(post, 'w', encoding='utf-8') as f:
f.write(content)
updated_count += 1
print(f"Updated: {post.name}")
return updated_count
def main():
print("Replacing thumbnail images with full-size versions...")
count = replace_thumbnails()
print(f"\n✅ Updated {count} posts")
if __name__ == "__main__":
main()