fluffle/app/templates_src/edit.lisp
2025-07-20 02:49:01 -04:00

122 lines
4.1 KiB
Common Lisp

(text "{% extends \"root.lisp\" %} {% block head %}")
(title
(text "{{ entry.slug }}"))
(text "{% endblock %} {% block body %}")
(div
("class" "flex items-center bar")
(button
("class" "button tab_button")
("id" "editor_tab_button")
("onclick" "tab_editor()")
(text "Edit"))
(button
("class" "button camo tab_button")
("id" "preview_tab_button")
("onclick" "tab_preview()")
(text "Preview")))
(div
("class" "card tab tabs")
(div
("id" "editor_tab")
("class" "tab fadein"))
(div
("id" "preview_tab")
("class" "tab fadein hidden")))
(form
("class" "w-full flex flex-col gap-2")
("style" "margin-top: var(--pad-2)")
("onsubmit" "edit_entry(event)")
(div
("class" "flex gap-2")
(input
("class" "w-full")
("type" "text")
("minlength" "2")
("name" "edit_code")
("required" "")
("placeholder" "Enter edit code"))
(input
("class" "w-full")
("type" "text")
("minlength" "2")
("name" "new_edit_code")
("placeholder" "New edit code"))
(input
("class" "w-full")
("type" "text")
("minlength" "2")
("name" "new_slug")
("placeholder" "New url")))
(div
("class" "w-full flex justify-between gap-2")
(div
("class" "flex gap-2")
(button
("class" "button green")
(text "Save"))
(a
("href" "/{{ entry.slug }}")
("class" "button")
(text "Back")))
(button
("class" "button red")
("ui_ident" "delete")
(text "Delete"))))
(text "{{ components::footer() }}")
; editor
(script ("src" "https://unpkg.com/codemirror@5.39.2/lib/codemirror.js"))
(script ("src" "https://unpkg.com/codemirror@5.39.2/mode/markdown/markdown.js"))
(script ("src" "https://unpkg.com/codemirror@5.39.2/addon/display/placeholder.js"))
(link ("rel" "stylesheet") ("href" "https://unpkg.com/codemirror@5.39.2/lib/codemirror.css"))
(script ("src" "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"))
(link ("rel" "stylesheet") ("href" "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/default.min.css"))
(script ("id" "editor_content") ("type" "text/markdown") (text "{{ entry.content|remove_script_tags|safe }}"))
(script
(text "setTimeout(() => {
globalThis.init_editor();
}, 150);
globalThis.edit_entry = (e) => {
e.preventDefault();
const rm = e.submitter.getAttribute(\"ui_ident\") === \"delete\";
if (rm && !confirm(\"Are you sure you want to do this?\")) {
return;
}
fetch(\"/api/v1/entries/{{ entry.slug }}\", {
method: \"POST\",
headers: {
\"Content-Type\": \"application/json\",
},
body: JSON.stringify({
content: globalThis.editor.getValue(),
edit_code: e.target.edit_code.value,
new_slug: e.target.new_slug.value || undefined,
new_edit_code: e.target.new_edit_code.value || undefined,
\"delete\": rm,
}),
})
.then(res => res.json())
.then((res) => {
if (res.ok) {
if (!rm) {
document.cookie = `Atto-Message=\"Entry updated\"; path=/`;
document.cookie = \"Atto-Message-Good=true; path=/\";
window.location.href = `/${res.payload}`;
} else {
document.cookie = `Atto-Message=\"Entry deleted\"; path=/`;
document.cookie = \"Atto-Message-Good=true; path=/\";
window.location.href = \"/\";
}
} else {
document.cookie = `Atto-Message=\"${res.message}\"; path=/`;
check_message();
}
})
}"))
(text "{% endblock %}")