chore: clean up repo

This commit is contained in:
trisua 2025-08-20 00:37:00 -04:00
parent 7d93dffaed
commit 92bc424361
11 changed files with 7 additions and 900 deletions

View file

@ -63,8 +63,8 @@ function get_cookie(key) {
function check_message() {
const element = document.getElementById("messages");
const message = get_cookie("Atto-Message");
const message_good = get_cookie("Atto-Message-Good") === "true";
const message = get_cookie("App-Message");
const message_good = get_cookie("App-Message-Good") === "true";
if (message) {
element.style.marginBottom = "1rem";
@ -88,151 +88,6 @@ globalThis.show_message = (message, message_good = true) => {
check_message();
// editor
globalThis.init_editor = (
name = "editor",
mode = "markdown",
element = "editor_tab",
content_element = "editor_content",
) => {
globalThis[name] = CodeMirror(document.getElementById(element), {
value: (document.getElementById(content_element) || { innerHTML: "" })
.innerHTML,
mode,
lineWrapping: true,
lineNumbers: false,
autoCloseBrackets: true,
autofocus: true,
viewportMargin: Number.POSITIVE_INFINITY,
inputStyle: "contenteditable",
highlightFormatting: false,
fencedCodeBlockHighlighting: false,
xml: false,
smartIndent: false,
indentUnit: 4,
tabSize: 4,
indentWithTabs: false,
placeholder: "",
extraKeys: {
Home: "goLineLeft",
End: "goLineRight",
Enter: (cm) => {
cm.replaceSelection("\n");
},
Tab: "insertSoftTab",
},
});
if (name === "editor") {
window.addEventListener("beforeunload", (e) => {
if (!globalThis.ALLOW_LEAVE) {
e.preventDefault();
return null;
}
});
}
};
globalThis.tab_editor = () => {
document.getElementById("editor_tab").classList.remove("hidden");
document.getElementById("preview_tab").classList.add("hidden");
document.getElementById("metadata_tab").classList.add("hidden");
document.getElementById("editor_tab_button").classList.remove("camo");
document.getElementById("preview_tab_button").classList.add("camo");
document.getElementById("metadata_tab_button").classList.add("camo");
if (document.getElementById("metadata_css")) {
document.getElementById("metadata_css").remove();
}
};
globalThis.get_preview = async () => {
return await (
await fetch("/api/v1/render", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
content: globalThis.editor.getValue(),
metadata: globalThis.metadata_editor.getValue(),
}),
})
).text();
};
globalThis.tab_preview = async () => {
if (
!document
.getElementById("preview_tab_button")
.classList.contains("camo")
) {
return;
}
// render
const res = await get_preview();
document.getElementById("preview_tab").innerHTML = res;
hljs.highlightAll();
// ...
document.getElementById("editor_tab").classList.add("hidden");
document.getElementById("preview_tab").classList.remove("hidden");
document.getElementById("metadata_tab").classList.add("hidden");
document.getElementById("editor_tab_button").classList.add("camo");
document.getElementById("preview_tab_button").classList.remove("camo");
document.getElementById("metadata_tab_button").classList.add("camo");
};
globalThis.first_time_on_metadata_tab = true;
globalThis.tab_metadata = () => {
document.getElementById("editor_tab").classList.add("hidden");
document.getElementById("preview_tab").classList.add("hidden");
document.getElementById("metadata_tab").classList.remove("hidden");
document.getElementById("editor_tab_button").classList.add("camo");
document.getElementById("preview_tab_button").classList.add("camo");
document.getElementById("metadata_tab_button").classList.remove("camo");
if (globalThis.first_time_on_metadata_tab) {
globalThis.metadata_editor.refresh();
}
globalThis.first_time_on_metadata_tab = false;
};
let exists_timeout = null;
globalThis.check_exists_input = (e) => {
if (exists_timeout) {
clearTimeout(exists_timeout);
}
exists_timeout = setTimeout(async () => {
if (e.target.value.length < 2 || e.target.value.length > 32) {
e.target.setCustomValidity("");
e.target.removeAttribute("data-invalid");
e.target.reportValidity();
return;
}
const exists = (
await (await fetch(`/api/v1/entries/${e.target.value}`)).json()
).payload;
console.log(exists);
if (exists) {
e.target.setCustomValidity("Slug is already in use");
e.target.setAttribute("data-invalid", "true");
} else {
e.target.setCustomValidity("");
e.target.removeAttribute("data-invalid");
}
e.target.reportValidity();
}, 1000);
};
// components
function close_dropdowns() {
for (const dropdown of Array.from(
@ -314,46 +169,6 @@ globalThis.init_dropdowns = (bind_to) => {
});
};
globalThis.METADATA_CSS_ENABLED = true;
globalThis.toggle_metadata_css = (e) => {
e.target.classList.add("yellow");
METADATA_CSS_ENABLED = !METADATA_CSS_ENABLED;
if (!METADATA_CSS_ENABLED) {
media_theme_pref(); // user user theme
document.getElementById("metadata_css").remove(); // remove css
// reset colored text
for (const element of Array.from(
document.querySelectorAll("#content_rect .color_block"),
)) {
element.removeAttribute("style");
element.classList.remove("color_block");
}
// strikethrough auto theme since it's disabled
if (document.getElementById("auto_theme")) {
document.getElementById("auto_theme").style.textDecoration =
"line-through";
}
// remove styles
for (const element of Array.from(
document.querySelectorAll("#content_rect style"),
)) {
element.remove();
}
for (const element of Array.from(
document.querySelectorAll("#content_rect [style]"),
)) {
element.removeAttribute("style");
}
} else {
window.location.reload();
}
};
globalThis.hash_check = (hash) => {
if (hash.startsWith("#/")) {
for (const x of Array.from(document.querySelectorAll(".subpage"))) {

View file

@ -580,157 +580,6 @@ span {
font-size: inherit;
}
/* codemirror/hljs */
.CodeMirror {
color: var(--color-text) !important;
}
.CodeMirror {
background: transparent !important;
font-family: inherit !important;
height: 10rem !important;
min-height: 100%;
max-height: 100%;
cursor: text;
}
.CodeMirror-cursor {
border-color: rgb(0, 0, 0) !important;
}
.CodeMirror-cursor:is(.dark *) {
border-color: rgb(255, 255, 255) !important;
}
.CodeMirror-cursor {
height: 22px !important;
}
[role="presentation"]::-moz-selection,
[role="presentation"] *::-moz-selection {
background-color: rgb(191, 219, 254) !important;
}
[role="presentation"]::selection,
[role="presentation"] *::selection,
.CodeMirror-selected {
background-color: rgb(191, 219, 254) !important;
}
[role="presentation"]:is(.dark *)::-moz-selection,
[role="presentation"] *:is(.dark *)::-moz-selection {
background-color: rgb(64, 64, 64) !important;
}
[role="presentation"]:is(.dark *)::selection,
[role="presentation"] *:is(.dark *)::selection,
.CodeMirror-selected:is(.dark *) {
background-color: rgb(64, 64, 64) !important;
}
.cm-header {
color: inherit !important;
}
.cm-variable-2,
.cm-quote,
.cm-keyword,
.cm-string,
.cm-atom,
.hljs-string {
color: rgb(63, 98, 18) !important;
}
.cm-variable-2:is(.dark *),
.cm-quote:is(.dark *),
.cm-keyword:is(.dark *),
.cm-string:is(.dark *),
.cm-atom:is(.dark *),
.hljs-string:is(.dark *) {
color: rgb(217, 249, 157) !important;
}
.cm-comment,
.hljs-keyword {
color: oklch(47% 0.157 37.304) !important;
}
.cm-comment:is(.dark *),
.hljs-keyword:is(.dark *) {
color: oklch(90.1% 0.076 70.697) !important;
}
.cm-link {
color: var(--color-link) !important;
}
.cm-url,
.cm-property,
.cm-qualifier,
.hljs-title {
color: rgb(29, 78, 216) !important;
}
.cm-url:is(.dark *),
.cm-property:is(.dark *),
.cm-qualifier:is(.dark *),
.hljs-title:is(.dark *) {
color: rgb(191, 219, 254) !important;
}
.cm-variable-3,
.cm-tag,
.cm-def,
.cm-attribute,
.cm-number,
.hljs-type {
color: rgb(91, 33, 182) !important;
}
.cm-variable-3:is(.dark *),
.cm-tag:is(.dark *),
.cm-def:is(.dark *),
.cm-attribute:is(.dark *),
.cm-number:is(.dark *),
.hljs-type:is(.dark *) {
color: rgb(221, 214, 254) !important;
}
.hljs-built_in {
color: var(--color-purple) !important;
}
.hljs-variable {
color: var(--color-link) !important;
}
.hljs-number {
color: var(--color-green) !important;
}
.hljs-link {
color: var(--color-link) !important;
}
.CodeMirror-scroll {
height: 100% !important;
}
.CodeMirror-line {
padding-left: 0 !important;
font-size: 16px !important;
}
.CodeMirror-focused .CodeMirror-placeholder {
opacity: 50%;
}
.hljs {
background: transparent !important;
color: inherit !important;
padding: 0 !important;
}
/* extra */
@keyframes fadein {
from {