const API = "/api/content-edits"; export function getPagePath() { const path = window.location.pathname.replace(/^\//, ""); if (!path || path.endsWith("/")) return "index.html"; return path; } export async function loadEdits(page = getPagePath()) { const res = await fetch(`${API}?page=${encodeURIComponent(page)}`); if (!res.ok) throw new Error("load failed"); return res.json(); } export async function saveEdits(payload) { const res = await fetch(`${API}?page=${encodeURIComponent(payload.page)}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); if (!res.ok) throw new Error("save failed"); return res.json(); } export function isContentEditHost() { const host = window.location.hostname; const ALLOWED_HOSTS = ["localhost", "127.0.0.1", "dev.mamadaevv.site", "f2ogw6fzi6trnp7cp43x8wsd.31.129.103.242.sslip.io"]; return ALLOWED_HOSTS.includes(host); }