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>
This commit is contained in:
67
replace_thumbnails.py
Normal file
67
replace_thumbnails.py
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/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: [](full-size)
|
||||
# Replace with just the full-size image: 
|
||||
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''
|
||||
|
||||
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''
|
||||
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()
|
Reference in New Issue
Block a user