Tech Blog

The Encoding Accident That Happened During Batch Text Editing, and Recovery via Full Regeneration

PowerShell Encoding Operations

Introduction

When batch-editing blog article Markdown files in Astro using PowerShell, an encoding misconfiguration caused all Japanese characters to become garbled.

This is the screen we were working on.

Film List Screen (Normal State)

What Happened

  • PowerShell’s Set-Content writes files as UTF-16 LE by default
  • Astro’s Content Collections expects UTF-8
  • As a result, all Japanese characters were corrupted

Recovery Method

All files were restored from the previous Git commit via checkout, then re-applied using [System.IO.File]::WriteAllText with explicit UTF-8 encoding.

We opened each screen — list, featured, ranking, and detail — in order, and visually verified that the Japanese text was displayed correctly.

Film List Screen (Normal State)

# Correct approach
[System.IO.File]::WriteAllText($path, $content, [System.Text.Encoding]::UTF8)

What We Learned

Always specify the encoding explicitly when writing files in PowerShell. Use Set-Content -Encoding UTF8 or [System.IO.File]::WriteAllText with UTF8.

Feel free to send a message

Please send a message if you have any technical questions, feedback, or inquiries.