ObsidianJustSharePlease/server/public/index.html

112 lines
5.4 KiB
HTML
Raw Normal View History

2023-06-25 18:16:06 +02:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Just Share Please</title>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.0/dist/jquery.min.js"></script>
2023-08-11 20:51:34 +02:00
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.0.5/dist/purify.js"></script>
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/highlight.min.js"></script>
2023-08-16 12:13:00 +02:00
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.min.js"></script>
2023-08-17 12:40:32 +02:00
<script src="https://cdn.jsdelivr.net/npm/markdown-it-texmath@1.0.0/texmath.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/markdown-it-anchor@8.6.7/dist/markdownItAnchor.umd.js"></script>
2023-09-08 17:35:11 +02:00
<script src="https://cdn.jsdelivr.net/npm/markdown-it-footnote@3.0.3/dist/markdown-it-footnote.min.js"></script>
2023-06-25 18:16:06 +02:00
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=JetBrains+Mono&display=swap">
2023-08-11 20:51:34 +02:00
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css">
2023-08-13 15:38:12 +02:00
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/styles/github-dark.min.css" media="(prefers-color-scheme: dark)">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/styles/github.min.css" media="not (prefers-color-scheme: dark)">
2023-08-11 22:49:12 +02:00
<link rel="stylesheet" href="style.css">
2023-06-25 18:16:06 +02:00
<link rel="icon" href="favicon.ico">
</head>
<body>
<div class="content">
<div id="main">
<script>
2023-08-16 12:13:00 +02:00
let md = markdownit({
html: true,
linkify: true,
langPrefix: "hljs language-",
highlight: (c, l) => {
const language = hljs.getLanguage(l) ? l : "plaintext";
return hljs.highlight(c, {language}).value;
}
2023-08-16 12:13:00 +02:00
});
md.use(texmath, {
engine: katex,
delimiters: ["dollars", "beg_end"]
});
2023-08-17 12:40:32 +02:00
md.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.linkInsideHeader({
placement: "after",
ariaHidden: true
}),
2023-09-08 17:35:11 +02:00
// prepend current file id to the anchor permalink
2023-09-25 22:37:38 +02:00
slugify: s => `${getId() ?? ""}-${encodeURIComponent(String(s).trim().toLowerCase().normalize("NFKD").replace(/\p{M}/g, "").replace(/\s+/g, "-").replace(/[^a-z0-9_-]/g, "")
)}`
2023-08-17 12:40:32 +02:00
});
2023-09-08 17:35:11 +02:00
md.use(markdownitFootnote);
let rulesToReplace = [
// prepend current file id to footnotes
["footnote_ref", [/href="#(fn\d+)"/, `href="#${getId() ?? ""}-$1"`]],
["footnote_open", [/id="(fn\d+)"/, `id="${getId() ?? ""}-$1"`]],
// prepend current file id to footnote refs
["footnote_ref", [/id="(fnref\d+)"/, `id="${getId() ?? ""}-$1"`]],
["footnote_anchor", [/href="#(fnref\d+)"/, `href="#${getId() ?? ""}-$1"`]]
];
for (let replacement of rulesToReplace) {
let prevRule = md.renderer.rules[replacement[0]];
md.renderer.rules[replacement[0]] = (tokens, idx, options, env, self) => {
return prevRule(tokens, idx, options, env, self).replace(...replacement[1]);
};
}
2023-08-11 20:51:34 +02:00
let main = $("#main");
2023-06-25 18:16:06 +02:00
$(window).on("hashchange", display);
display();
function display() {
main.html(`<div class="center-message"><p>Loading...</p></div>`);
2023-08-17 12:40:32 +02:00
let id = getId();
2023-06-25 18:16:06 +02:00
$.ajax({
2023-08-09 20:13:44 +02:00
method: "get",
2023-08-17 12:40:32 +02:00
url: id ? `share.php?id=${id}` : "index.md",
success: t => {
main.html(DOMPurify.sanitize(md.render(t)));
// scroll to anchor
$(() => {
let element = $(window.location.hash);
if (element.length)
$(window).scrollTop(element.offset().top);
});
2023-08-17 12:40:32 +02:00
},
error: (r, s, e) => main.html(`<div class="center-message"><p>Error loading shared note with id <code>${id}</code>: ${e}</p><p><a href="#">Home</a></p></div>`)
2023-06-25 18:16:06 +02:00
});
}
2023-08-17 12:40:32 +02:00
function getId() {
let hash = window.location.hash;
if (!hash)
return undefined;
// hashes consist of the file id, a dash and then the permalink anchor name
let dash = hash.indexOf("-");
return hash.substring(1, dash > 0 ? dash : hash.length);
}
2023-06-25 18:16:06 +02:00
</script>
</div>
<div id="footer">
2023-08-17 12:40:32 +02:00
Created using <a href="/">Just Share Please</a> for <a href="https://obsidian.md">Obsidian</a>
2023-06-25 18:16:06 +02:00
</div>
</div>
</body>
</html>