add: journal.css special note
This commit is contained in:
parent
f0d1a1e8e4
commit
dc50f3a8af
8 changed files with 125 additions and 13 deletions
|
@ -9,6 +9,11 @@
|
|||
; redirect to journal homepage
|
||||
(meta ("http-equiv" "refresh") ("content" "0; url=/@{{ user.username }}/{{ journal.title }}"))
|
||||
(text "{%- endif %} {%- endif %}")
|
||||
|
||||
(text "{% if view_mode and journal -%}")
|
||||
; add journal css
|
||||
(link ("rel" "stylesheet") ("data-turbo-temporary" "true") ("href" "/api/v1/journals/{{ journal.id }}/journal.css?v=tetratto-{{ random_cache_breaker }}"))
|
||||
(text "{%- endif %}")
|
||||
(text "{% endblock %} {% block body %} {{ macros::nav(selected=\"journals\") }}")
|
||||
(text "{% if not view_mode -%}")
|
||||
(nav
|
||||
|
@ -73,7 +78,7 @@
|
|||
(b (text "{{ note.title }}"))
|
||||
(text "{%- endif %}"))
|
||||
|
||||
(text "{% if user and user.id == journal.owner -%}")
|
||||
(text "{% if user and user.id == journal.owner and (not note or note.title != \"journal.css\") -%}")
|
||||
(div
|
||||
("class" "pillmenu")
|
||||
(a
|
||||
|
@ -181,10 +186,36 @@
|
|||
; import codemirror
|
||||
(script ("src" "https://unpkg.com/codemirror@5.39.2/lib/codemirror.js") ("data-turbo-temporary" "true"))
|
||||
(script ("src" "https://unpkg.com/codemirror@5.39.2/addon/display/placeholder.js") ("data-turbo-temporary" "true"))
|
||||
(script ("src" "https://unpkg.com/codemirror@5.39.2/mode/markdown/markdown.js") ("data-turbo-temporary" "true"))
|
||||
(link ("rel" "stylesheet") ("href" "https://unpkg.com/codemirror@5.39.2/lib/codemirror.css") ("data-turbo-temporary" "true"))
|
||||
|
||||
(text "{% if note.title == \"journal.css\" -%}")
|
||||
; css editor
|
||||
(script ("src" "https://unpkg.com/codemirror@5.39.2/addon/edit/closebrackets.js") ("data-turbo-temporary" "true"))
|
||||
(script ("src" "https://unpkg.com/codemirror@5.39.2/addon/hint/css-hint.js") ("data-turbo-temporary" "true"))
|
||||
(script ("src" "https://unpkg.com/codemirror@5.39.2/addon/hint/show-hint.js") ("data-turbo-temporary" "true"))
|
||||
(script ("src" "https://unpkg.com/codemirror@5.39.2/addon/lint/css-lint.js") ("data-turbo-temporary" "true"))
|
||||
(script ("src" "https://unpkg.com/codemirror@5.39.2/mode/css/css.js") ("data-turbo-temporary" "true"))
|
||||
(link ("rel" "stylesheet") ("href" "https://unpkg.com/codemirror@5.39.2/addon/hint/show-hint.css") ("data-turbo-temporary" "true"))
|
||||
(link ("rel" "stylesheet") ("href" "https://unpkg.com/codemirror@5.39.2/addon/lint/lint.css") ("data-turbo-temporary" "true"))
|
||||
|
||||
(style
|
||||
(text ".CodeMirror {
|
||||
font-family: monospace !important;
|
||||
font-size: 16px;
|
||||
border: solid 1px var(--color-super-lowered);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.CodeMirror-line {
|
||||
padding-left: 5px !important;
|
||||
}"))
|
||||
(text "{% else %}")
|
||||
; markdown editor
|
||||
(script ("src" "https://unpkg.com/codemirror@5.39.2/mode/markdown/markdown.js") ("data-turbo-temporary" "true"))
|
||||
(text "{%- endif %}")
|
||||
|
||||
; tab bar
|
||||
(text "{% if note.title != \"journal.css\" -%}")
|
||||
(div
|
||||
("class" "pillmenu")
|
||||
(a
|
||||
|
@ -199,6 +230,7 @@
|
|||
("data-tab-button" "preview")
|
||||
("data-turbo" "false")
|
||||
(str (text "journals:label.preview_pane"))))
|
||||
(text "{%- endif %}")
|
||||
|
||||
; tabs
|
||||
(div
|
||||
|
@ -222,10 +254,15 @@
|
|||
(script ("id" "editor_content") ("type" "text/markdown") (text "{{ note.content|remove_script_tags|safe }}"))
|
||||
(script
|
||||
(text "setTimeout(() => {
|
||||
if (!document.getElementById(\"preview_tab\").shadowRoot) {
|
||||
document.getElementById(\"preview_tab\").attachShadow({ mode: \"open\" });
|
||||
}
|
||||
|
||||
globalThis.editor = CodeMirror(document.getElementById(\"editor_tab\"), {
|
||||
value: document.getElementById(\"editor_content\").innerHTML,
|
||||
mode: \"markdown\",
|
||||
mode: \"{% if note.title == 'journal.css' -%} css {%- else -%} markdown {%- endif %}\",
|
||||
lineWrapping: true,
|
||||
lineNumbers: \"{{ note.title }}\" === \"journal.css\",
|
||||
autoCloseBrackets: true,
|
||||
autofocus: true,
|
||||
viewportMargin: Number.POSITIVE_INFINITY,
|
||||
|
@ -233,7 +270,8 @@
|
|||
highlightFormatting: false,
|
||||
fencedCodeBlockHighlighting: false,
|
||||
xml: false,
|
||||
smartIndent: false,
|
||||
smartIndent: true,
|
||||
indentUnit: 4,
|
||||
placeholder: `# {{ note.title }}`,
|
||||
extraKeys: {
|
||||
Home: \"goLineLeft\",
|
||||
|
@ -244,6 +282,15 @@
|
|||
},
|
||||
});
|
||||
|
||||
editor.on(\"keydown\", (cm, e) => {
|
||||
if (e.key.length > 1) {
|
||||
// ignore all keys that aren't a letter
|
||||
return;
|
||||
}
|
||||
|
||||
CodeMirror.showHint(cm, CodeMirror.hint.css);
|
||||
});
|
||||
|
||||
document.querySelector(\"[data-tab-button=editor]\").addEventListener(\"click\", async (e) => {
|
||||
e.preventDefault();
|
||||
trigger(\"atto::hooks::tabs:switch\", [\"editor\"]);
|
||||
|
@ -263,7 +310,10 @@
|
|||
})
|
||||
).text();
|
||||
|
||||
document.getElementById(\"preview_tab\").innerHTML = res;
|
||||
const preview_token = window.crypto.randomUUID();
|
||||
document.getElementById(\"preview_tab\").shadowRoot.innerHTML = `${res}<style>
|
||||
@import url(\"/api/v1/journals/{{ journal.id }}/journal.css?v=preview-${preview_token}\");
|
||||
</style>`;
|
||||
trigger(\"atto::hooks::tabs:switch\", [\"preview\"]);
|
||||
});
|
||||
}, 150);"))
|
||||
|
@ -360,7 +410,7 @@
|
|||
},
|
||||
body: JSON.stringify({
|
||||
title,
|
||||
content: `# ${title}`,
|
||||
content: title === \"journal.css\" ? `/* ${title} */\\n` : `# ${title}`,
|
||||
journal: \"{{ selected_journal }}\",
|
||||
}),
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue