This commit is contained in:
trisua 2025-07-20 02:49:01 -04:00
commit 94cec33b46
8 changed files with 1011 additions and 0 deletions

View file

@ -0,0 +1,40 @@
(text "{% macro footer() -%}")
(footer
("class" "flex flex-col items-center gap-2")
(hr ("style" "min-width: 20rem; margin-top: calc(var(--pad-4) * 4)"))
(div
("class" "w-full flex justify-between")
(div ("style" "width: 50px"))
(div
("class" "flex flex-col gap-2 items-center")
(div
("class" "flex gap-2 flex-wrap")
(a
("href" "/")
(text "new"))
(a
("href" "/what")
(text "what"))
(a
("href" "https://trisua.com/t/attobin")
(text "source")))
(span ("style" "font-size: 14px") ("class" "fade") (text "{{ name }}")))
; theme switches
(button
("class" "button camo fade")
("id" "switch_light")
("title" "Switch theme")
("onclick" "set_theme('Dark')")
(text "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-sun-icon lucide-sun icon\"><circle cx=\"12\" cy=\"12\" r=\"4\"/><path d=\"M12 2v2\"/><path d=\"M12 20v2\"/><path d=\"m4.93 4.93 1.41 1.41\"/><path d=\"m17.66 17.66 1.41 1.41\"/><path d=\"M2 12h2\"/><path d=\"M20 12h2\"/><path d=\"m6.34 17.66-1.41 1.41\"/><path d=\"m19.07 4.93-1.41 1.41\"/></svg>"))
(button
("class" "button camo fade hidden")
("id" "switch_dark")
("title" "Switch theme")
("onclick" "set_theme('Light')")
(text "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-moon-icon lucide-moon icon\"><path d=\"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z\"/></svg>"))))
(text "{%- endmacro %}")

122
app/templates_src/edit.lisp Normal file
View file

@ -0,0 +1,122 @@
(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 %}")

View file

@ -0,0 +1,9 @@
(text "{% extends \"root.lisp\" %} {% block head %}")
(title
(text "Error - {{ name }}"))
(text "{% endblock %} {% block body %}")
(div
("class" "card")
(p (text "{{ error }}")))
(text "{{ components::footer() }}")
(text "{% endblock %}")

View file

@ -0,0 +1,87 @@
(text "{% extends \"root.lisp\" %} {% block head %}")
(title
(text "{{ name }}"))
(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 justify-between gap-2 flex-collapse-rev")
("style" "margin-top: var(--pad-2)")
("onsubmit" "create_entry(event)")
(button
("class" "button")
(text "Go"))
(div
("class" "flex gap-2")
(input
("class" "w-full")
("type" "text")
("minlength" "2")
("name" "edit_code")
("placeholder" "Custom edit code"))
(input
("class" "w-full")
("type" "text")
("minlength" "2")
("maxlength" "32")
("name" "slug")
("placeholder" "Custom url"))))
(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
(text "setTimeout(() => {
globalThis.init_editor();
}, 150);
globalThis.create_entry = (e) => {
e.preventDefault();
fetch(\"/api/v1/entries\", {
method: \"POST\",
headers: {
\"Content-Type\": \"application/json\",
},
body: JSON.stringify({
content: globalThis.editor.getValue(),
slug: e.target.slug.value || undefined,
edit_code: e.target.edit_code.value || undefined,
}),
})
.then(res => res.json())
.then((res) => {
if (res.ok) {
document.cookie = `Atto-Message=\"Entry created! Your edit code: <code>${res.payload[1]}</code>.\"; path=/`;
document.cookie = \"Atto-Message-Good=true; path=/\";
window.location.href = `/${res.payload[0]}`;
} else {
document.cookie = `Atto-Message=\"${res.message}\"; path=/`;
check_message();
}
})
}"))
(text "{% endblock %}")

View file

@ -0,0 +1,28 @@
(text "{%- import \"components.lisp\" as components -%}")
(text "<!doctype html>")
(html
("lang" "en")
(head
(meta ("charset" "UTF-8"))
(meta ("name" "viewport") ("content" "width=device-width, initial-scale=1.0"))
(meta ("http-equiv" "X-UA-Compatible") ("content" "ie=edge"))
(link ("rel" "icon") ("href" "/public/favicon.svg"))
(link ("rel" "stylesheet") ("href" "{{ tetratto }}/css/utility.css"))
(link ("rel" "stylesheet") ("href" "/public/style.css"))
(meta ("name" "theme-color") ("content" "#fbc27f"))
(meta ("name" "description") ("content" "{{ name }}"))
(meta ("property" "og:type") ("content" "website"))
(meta ("property" "og:site_name") ("content" "{{ name }}"))
(script ("src" "/public/app.js") ("defer"))
(text "{% block head %}{% endblock %}"))
(body
(article
("class" "content_container flex flex-col")
("id" "page")
(ul ("id" "messages"))
(text "{% block body %}{% endblock %}"))))

View file

@ -0,0 +1,29 @@
(text "{% extends \"root.lisp\" %} {% block head %}")
(title
(text "{{ entry.slug }}"))
(text "{% endblock %} {% block body %}")
(div
("class" "flex flex-col gap-2")
(div
("class" "card")
("style" "min-height: 15rem")
(text "{{ entry.content|markdown|safe }}"))
(div
("class" "w-full flex justify-between gap-2")
(a
("class" "button")
("href" "/{{ entry.slug }}/edit")
(text "Edit"))
(div
("class" "flex flex-col gap-1 items-end fade")
(span (text "Pub: {{ entry.created / 1000|int|date(format=\"%Y-%m-%d %H:%M\", timezone=\"Etc/UTC\") }} UTC"))
(span (text "Edit: {{ entry.edited / 1000|int|date(format=\"%Y-%m-%d %H:%M\", timezone=\"Etc/UTC\") }} UTC"))
(span (text "Views: {{ views }}")))))
(link ("rel" "stylesheet") ("href" "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/default.min.css"))
(script ("src" "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"))
(script (text "hljs.highlightAll();"))
(text "{{ components::footer() }}")
(text "{% endblock %}")