fluffle/app/templates_src/edit.lisp

154 lines
5.4 KiB
Common Lisp
Raw Normal View History

2025-07-20 02:49:01 -04:00
(text "{% extends \"root.lisp\" %} {% block head %}")
(title
(text "{{ entry.slug }}"))
2025-07-21 02:11:23 -04:00
(link ("rel" "icon") ("href" "/public/favicon.svg"))
2025-07-20 02:49:01 -04:00
(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()")
2025-07-21 02:11:23 -04:00
(text "Preview"))
(button
("class" "button camo tab_button")
("id" "metadata_tab_button")
("onclick" "tab_metadata()")
2025-07-25 15:12:15 -04:00
(text "Metadata")
(a
("class" "button simple surface")
("href" "/docs/metadata")
("target" "_blank")
("title" "Info")
(text "i"))))
2025-07-20 02:49:01 -04:00
(div
2025-07-24 01:06:03 -04:00
("class" "card tab tabs container")
("id" "tabs_group")
2025-07-20 02:49:01 -04:00
(div
("id" "editor_tab")
("class" "tab fadein"))
(div
("id" "preview_tab")
2025-07-24 01:06:03 -04:00
("class" "tab fadein hidden"))
2025-07-21 02:11:23 -04:00
(div
("id" "metadata_tab")
2025-07-20 02:49:01 -04:00
("class" "tab fadein hidden")))
(form
("class" "w-full flex flex-col gap-2")
("style" "margin-top: var(--pad-2)")
("onsubmit" "edit_entry(event)")
(div
2025-07-26 01:01:45 -04:00
("class" "w-full flex gap-2")
2025-07-20 02:49:01 -04:00
(input
("class" "w-full")
("type" "text")
("minlength" "2")
("name" "edit_code")
("required" "")
("placeholder" "Enter edit code"))
2025-07-26 01:01:45 -04:00
(input ("class" "w-full") ("style" "visibility: hidden") ("aria-hidden" "true") ("disabled" "true"))
(input ("class" "w-full") ("style" "visibility: hidden") ("aria-hidden" "true") ("disabled" "true")))
(div
("class" "flex gap-2")
2025-07-20 02:49:01 -04:00
(input
("class" "w-full")
("type" "text")
("minlength" "2")
("name" "new_edit_code")
("placeholder" "New edit code"))
2025-07-26 01:01:45 -04:00
(input
("class" "w-full")
("type" "text")
("minlength" "2")
("name" "new_modify_code")
("placeholder" "New modify code"))
2025-07-20 02:49:01 -04:00
(input
("class" "w-full")
("type" "text")
("minlength" "2")
("name" "new_slug")
2025-07-20 20:43:01 -04:00
("oninput" "check_exists_input(event)")
2025-07-20 02:49:01 -04:00
("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"))))
; 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 }}"))
2025-07-21 02:11:23 -04:00
(script ("id" "editor_metadata_content") ("type" "text/markdown") (text "{{ entry.metadata|remove_script_tags|safe }}"))
2025-07-20 02:49:01 -04:00
(script
(text "setTimeout(() => {
globalThis.init_editor();
2025-07-21 02:11:23 -04:00
globalThis.init_editor(\"metadata_editor\", \"plain\", \"metadata_tab\", \"editor_metadata_content\");
2025-07-20 02:49:01 -04:00
}, 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,
2025-07-26 01:01:45 -04:00
new_modify_code: e.target.new_modify_code.value || undefined,
2025-07-21 02:11:23 -04:00
metadata: globalThis.metadata_editor.getValue(),
2025-07-20 02:49:01 -04:00
\"delete\": rm,
}),
})
.then(res => res.json())
.then((res) => {
if (res.ok) {
2025-07-20 03:24:55 -04:00
globalThis.ALLOW_LEAVE = true;
2025-07-20 02:49:01 -04:00
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 {
2025-07-21 02:11:23 -04:00
show_message(res.message, false);
2025-07-20 02:49:01 -04:00
}
})
}"))
(text "{% endblock %}")