1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-12-02 20:22:52 +00:00

file parsing and previewing

This commit is contained in:
Laura
2025-11-04 00:23:29 +01:00
parent 41210d0b36
commit 9f983f3034
13 changed files with 439 additions and 10 deletions

44
internal/preview.html Normal file
View File

@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="/lib/catppuccin.min.css" rel="stylesheet" />
<link href="/css/preview.css" rel="stylesheet" />
<title>File Preview</title>
<script>
const data = {{ . | json }};
</script>
</head>
<body>
<pre><code></code></pre>
<script src="/lib/highlight.min.js"></script>
<script>
const title = document.querySelector("title"),
body = document.querySelector("code");
title.innerText = data.name;
body.innerHTML = hljs.highlightAuto(data.content).value;
addEventListener("keydown", event => {
if ((event.ctrlKey || event.metaKey) && event.key === "S") {
event.preventDefault();
const el = document.createElement("a");
el.download = data.name;
el.href = `data:text/plain;base64,${btoa(data.content)}`;
el.click();
} else if (event.key === "Escape") {
window.close();
}
});
</script>
</body>
</html>