diff options
| author | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-10-26 22:38:07 +0900 |
|---|---|---|
| committer | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-10-26 22:38:07 +0900 |
| commit | cdb4fa36a8b4230425f3d5bf001d73a8b467450b (patch) | |
| tree | b1673c3268d437e4dce9ad70fdd87d95e2353c01 /scripts/park-editor.mjs | |
| parent | fa73b6a9f36268986af68192f65978539f4d059c (diff) | |
kodaira-parks.json: 公園情報を更新し、文字化けを修復
文字化けした9公園のキー・値を復元。時計の1を○に正規化。
park-editorは保存前にU+FFFDを検査し、一時ファイル経由で書き込む。
Diffstat (limited to 'scripts/park-editor.mjs')
| -rw-r--r-- | scripts/park-editor.mjs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/scripts/park-editor.mjs b/scripts/park-editor.mjs index a872008..d0c08da 100644 --- a/scripts/park-editor.mjs +++ b/scripts/park-editor.mjs @@ -9,7 +9,7 @@ // // 注意: ローカル(127.0.0.1)にのみ公開します。追加パッケージは不要です。 import { createServer } from "node:http"; -import { readFile, writeFile } from "node:fs/promises"; +import { readFile, writeFile, rename } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; @@ -103,7 +103,14 @@ const server = createServer(async (req, res) => { const text = target.dataset.pretty ? `${JSON.stringify(data, null, 2)}\n` : `${JSON.stringify(data)}\n`; - await writeFile(target.dataset.path, text, "utf-8"); + if (text.includes("\uFFFD")) { + throw new Error( + "文字化け(U+FFFD)が含まれているため保存を中止しました。入力内容を確認してください。", + ); + } + const tmp = `${target.dataset.path}.tmp`; + await writeFile(tmp, text, "utf-8"); + await rename(tmp, target.dataset.path); const count = target.id === "nearbyParks" ? data.features.length : data.length; console.log(`保存しました: ${target.dataset.label} ${count}件 → ${target.dataset.path}`); |
