From a4840999cdd042179452e03ef831929dac5d3c6d Mon Sep 17 00:00:00 2001
From: Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>
Date: Wed, 7 Oct 2026 23:10:30 +0900
Subject: park-editor: 公園データを編集するローカルツールを追加
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
scripts/park-editor.html | 148 +++++++++++++++++++++++++++++++++++++++++++++++
scripts/park-editor.mjs | 54 +++++++++++++++++
2 files changed, 202 insertions(+)
create mode 100644 scripts/park-editor.html
create mode 100644 scripts/park-editor.mjs
(limited to 'scripts')
diff --git a/scripts/park-editor.html b/scripts/park-editor.html
new file mode 100644
index 0000000..01df13f
--- /dev/null
+++ b/scripts/park-editor.html
@@ -0,0 +1,148 @@
+
+
+
+
+
+公園データ編集
+
+
+
+
+
+
+
+
diff --git a/scripts/park-editor.mjs b/scripts/park-editor.mjs
new file mode 100644
index 0000000..7a6c2fa
--- /dev/null
+++ b/scripts/park-editor.mjs
@@ -0,0 +1,54 @@
+// 公園データの簡易エディタ(ローカル専用)。
+//
+// 使い方:
+// node scripts/park-editor.mjs
+// → 表示された URL(既定 http://localhost:8787/)をブラウザで開く
+// → 表のセルを直接編集し、「保存」を押すと src/data/kodaira-parks.json を更新
+// → 反映確認後、git にコミットする
+//
+// 注意: ローカル(127.0.0.1)にのみ公開します。追加パッケージは不要です。
+import { createServer } from "node:http";
+import { readFile, writeFile } from "node:fs/promises";
+import { fileURLToPath } from "node:url";
+import { dirname, join } from "node:path";
+
+const root = join(dirname(fileURLToPath(import.meta.url)), "..");
+const DATA = join(root, "src/data/kodaira-parks.json");
+const HTML = join(root, "scripts/park-editor.html");
+const PORT = Number(process.env.PORT || 8787);
+
+function send(res, code, type, body) {
+ res.writeHead(code, { "content-type": type });
+ res.end(body);
+}
+
+const server = createServer(async (req, res) => {
+ try {
+ const url = (req.url || "").split("?")[0];
+ if (req.method === "GET" && (url === "/" || url === "/index.html")) {
+ send(res, 200, "text/html; charset=utf-8", await readFile(HTML, "utf-8"));
+ } else if (req.method === "GET" && url === "/api/parks") {
+ send(res, 200, "application/json; charset=utf-8", await readFile(DATA, "utf-8"));
+ } else if (req.method === "POST" && url === "/api/parks") {
+ let body = "";
+ for await (const chunk of req) body += chunk;
+ const parks = JSON.parse(body);
+ if (!Array.isArray(parks) || parks.length === 0) {
+ throw new Error("データが配列ではありません");
+ }
+ // 元ファイルと同じコンパクトな1行JSONで保存する(日本語はそのまま)。
+ await writeFile(DATA, JSON.stringify(parks), "utf-8");
+ console.log(`保存しました: ${parks.length} 件 → ${DATA}`);
+ send(res, 200, "application/json; charset=utf-8", JSON.stringify({ ok: true, count: parks.length }));
+ } else {
+ send(res, 404, "text/plain; charset=utf-8", "not found");
+ }
+ } catch (e) {
+ console.error(e);
+ send(res, 500, "text/plain; charset=utf-8", String(e));
+ }
+});
+
+server.listen(PORT, "127.0.0.1", () => {
+ console.log(`公園データ編集: http://localhost:${PORT}/ (Ctrl+C で終了)`);
+});
--
cgit v1.3.1