feat: Add web view to display notes in HTML
All checks were successful
/ pre-commit (push) Successful in 2m59s
All checks were successful
/ pre-commit (push) Successful in 2m59s
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
a5ebf7607c
commit
8edaebfad6
3 changed files with 159 additions and 2 deletions
|
@ -12,7 +12,7 @@
|
|||
<div class="alert alert-success" role="alert">
|
||||
<p>Note created successfully</p>
|
||||
<p>
|
||||
<a href="{{.URL}}">{{.URL}}</a>
|
||||
<a href="{{.URL}}.html">{{.URL}}.html</a>
|
||||
</p>
|
||||
</div>
|
||||
{{else}}
|
||||
|
@ -20,8 +20,8 @@
|
|||
<p>Could not create note</p>
|
||||
<p><strong>{{.Err}}</strong></p>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{block "footer" .}}{{end}}
|
||||
</body>
|
||||
|
|
64
src/server/templates/note.html
Normal file
64
src/server/templates/note.html
Normal file
|
@ -0,0 +1,64 @@
|
|||
{{define "note"}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-bs-theme="light">
|
||||
|
||||
{{block "head" .}}{{end}}
|
||||
|
||||
<body>
|
||||
{{block "header" .}}{{end}}
|
||||
|
||||
{{if ne .Err nil}}
|
||||
<div class="container mb-4 text-center">
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<p>Could not show note</p>
|
||||
<p><strong>{{.Err}}</strong></p>
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="container mb-4">
|
||||
<div class="d-flex flex-wrap py-2">
|
||||
<span class="fs-4 d-flex mb-3 mb-md-0 me-md-auto text-decoration-none">Note {{.Note.ID}}</span>
|
||||
<ul class="nav nav-pills align-items-center">
|
||||
<li class="nav-item">
|
||||
<a href="" id="rawURL">raw</a>
|
||||
<script>document.getElementById("rawURL").href = window.location.href.replace(".html", "");</script>
|
||||
</li>
|
||||
<li class="nav-item px-2">
|
||||
{{.Note.Language}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div id="editor" name="editor" class="form-control"
|
||||
style="height: 300px; resize: vertical; overflow: auto;"></div>
|
||||
</div>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs/loader.min.js"></script>
|
||||
<script>
|
||||
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs' } });
|
||||
|
||||
require(['vs/editor/editor.main'], function () {
|
||||
var editor = monaco.editor.create(document.getElementById('editor'), {
|
||||
theme: document.documentElement.getAttribute('data-bs-theme') == 'light' ? "vs" : "vs-dark",
|
||||
language: "{{.Note.Language}}",
|
||||
readOnly: true,
|
||||
value: "{{string .Note.Content}}"
|
||||
});
|
||||
|
||||
// Dark mode
|
||||
document.getElementById("lightSwitch").addEventListener("click", () => {
|
||||
if (document.documentElement.getAttribute('data-bs-theme') == 'light') {
|
||||
monaco.editor.setTheme("vs")
|
||||
} else if (document.documentElement.getAttribute('data-bs-theme') == 'dark') {
|
||||
monaco.editor.setTheme("vs-dark")
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{block "footer" .}}{{end}}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
{{end}}
|
Loading…
Add table
Add a link
Reference in a new issue