From cdb4fa36a8b4230425f3d5bf001d73a8b467450b Mon Sep 17 00:00:00 2001 From: Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:38:07 +0900 Subject: kodaira-parks.json: 公園情報を更新し、文字化けを修復 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 文字化けした9公園のキー・値を復元。時計の1を○に正規化。 park-editorは保存前にU+FFFDを検査し、一時ファイル経由で書き込む。 --- scripts/park-editor.mjs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'scripts') 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}`); -- cgit v1.3.1