From 0149c132bbbaa3324d1a6900a1ebf31653c91d9e Mon Sep 17 00:00:00 2001 From: Archicratia Date: Mon, 19 Jan 2026 19:28:35 +0100 Subject: [PATCH] Modal: open antifragile + Category clear + popup fallback --- src/components/ProposeModal.astro | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/components/ProposeModal.astro b/src/components/ProposeModal.astro index a2481c8..976d5a1 100644 --- a/src/components/ProposeModal.astro +++ b/src/components/ProposeModal.astro @@ -95,9 +95,26 @@ /** @type {"correction"|"fact"|""} */ let kind = ""; + const esc = (s) => String(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + const upsertLine = (text, key, value) => { - const re = new RegExp(`^\\s*${key}\\s*:\\s*.*$`, "mi"); + const re = new RegExp(`^\\s*${esc(key)}\\s*:\\s*.*$`, "mi"); + + // value vide => supprimer la ligne si elle existe + if (!value) { + if (!re.test(text)) return text; + return ( + text + .replace(re, "") + .replace(/\n{3,}/g, "\n\n") + .trimEnd() + "\n" + ); + } + + // remplace si existe if (re.test(text)) return text.replace(re, `${key}: ${value}`); + + // sinon append const sep = text && !text.endsWith("\n") ? "\n" : ""; return text + sep + `${key}: ${value}\n`; }; @@ -171,12 +188,16 @@ const cat = btn.getAttribute("data-category") || ""; let body = pending.searchParams.get("body") || ""; - if (cat) body = upsertLine(body, "Category", cat); + body = upsertLine(body, "Category", cat); + pending.searchParams.set("body", body); + const u = pending.toString(); dlg.close(); - window.open(pending.toString(), "_blank", "noopener,noreferrer"); + + const w = window.open(u, "_blank", "noopener,noreferrer"); + if (!w) window.location.href = u; }); })();