You are updating Hugo markdown blog posts to fix title capitalization and migrate WordPress images to the correct Hugo directory structure.
Given a migrated blog post file:
- Convert titles and subtitles to Title Case
- Find all wp-content image references
- Copy referenced images from WordPress directory to Hugo static directory
- Update image paths in the markdown
Read the provided markdown file path.
-
Frontmatter title: Convert to Title Case
- Preserve acronyms (SQL, DBA, etc.)
- Preserve brand names (dbatools, PowerShell, etc.)
- Use proper title capitalization rules (lowercase articles, conjunctions, prepositions unless first/last word)
-
Markdown headers (## Subtitle, ### Sub-subtitle):
- Convert all headers to Title Case using same rules
- Preserve code snippets in backticks unchanged
-
Scan the markdown for all wp-content references:
- Look for patterns like:
 - Look for HTML img tags:
<img src="https://dbatools.io/wp-content/uploads/..."> - Look for relative paths:
/wp-content/uploads/...
- Look for patterns like:
-
For each wp-content reference found:
- Extract the relative path after
/wp-content/ - Build source path:
S:\github\old\web\wp-content\{relative-path} - Extract filename from path
- Build destination path:
static/images/{filename}(root of static/images) - Copy the file from source to destination
- Use bash to copy:
cp "source" "destination" - Handle missing source files gracefully (log warning, continue)
- Don't overwrite if destination exists (unless filesizes differ)
- Use bash to copy:
- Update the markdown to reference new path:
- Old:
https://dbatools.io/wp-content/uploads/2018/04/image.png - New:
/images/image.png
- Old:
- Extract the relative path after
- CRITICAL: OVERWRITE the original file with the updated content
- Use
str_replacefor targeted changes or recreate entire file - Preserve all content exactly except for:
- Title case conversions
- Updated image paths
- Ensure no formatting is lost
Before:
---
title: "three ways to track logins using dbatools"
date: 2018-04-10
---
## how to monitor your database
After:
---
title: "Three Ways to Track Logins Using dbatools"
date: 2018-04-10
---
## How to Monitor Your Database
File operation:
- Copied:
S:\github\old\web\wp-content\uploads\2018\04\login-tracking.png→static/images/login-tracking.png
- Always write changes back to the file - do not just display output
- Handle multiple images per file
- Preserve exact markdown formatting
- If image copy fails, note the error but continue processing
- Common WordPress image patterns:
/wp-content/uploads/YYYY/MM/filename.ext- Can be .png, .jpg, .jpeg, .gif, .webp, .svg
- Check if
static/images/directory exists, create if needed - If filename collision occurs in destination, check file sizes:
- If identical size, skip copy
- If different size, append number:
filename-2.png
After completing the update, confirm:
- Title updated: [Old Title] → [New Title]
- Headers updated: [count]
- Images processed: [count]
- Successfully copied: [count]
- Failed/skipped: [count]
- File updated: [filepath]
- Missing source images: Log warning, update path anyway (may be handled separately)
- Failed file copies: Log error, continue with remaining images
- Permission errors: Report clearly with full paths